Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common CLI configuration error categories #2130

Merged
merged 17 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/debug-artifacts-failure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
shell: bash
run: |
LANGUAGES="cpp csharp go java javascript python"
pushd "./my-debug-artifacts"
cd "./my-debug-artifacts"
echo "Artifacts from run:"
for language in $LANGUAGES; do
echo "- Checking $language"
Expand All @@ -82,6 +82,5 @@ jobs:
exit 1
fi
done
popd
env:
GO111MODULE: auto
37 changes: 36 additions & 1 deletion lib/cli-errors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/cli-errors.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

37 changes: 36 additions & 1 deletion src/cli-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ function ensureEndsInPeriod(text: string): string {

/** Error messages from the CLI that we consider configuration errors and handle specially. */
export enum CliConfigErrorCategory {
DetectedCodeButCouldNotProcess = "DetectedCodeButCouldNotProcess",
IncompatibleWithActionVersion = "IncompatibleWithActionVersion",
InitCalledTwice = "InitCalledTwice",
InvalidSourceRoot = "InvalidSourceRoot",
NoJavaScriptTypeScriptCodeFound = "NoJavaScriptTypeScriptCodeFound",
NoBuildCommandAutodetected = "NoBuildCommandAutodetected",
NoBuildMethodAutodetected = "NoBuildMethodAutodetected",
NoSupportedBuildCommandSucceeded = "NoSupportedBuildCommandSucceeded",
NoSupportedBuildSystemDetected = "NoSupportedBuildSystemDetected",
NoSupportedLanguagesDetected = "NoSupportedLanguagesDetected",
}

type CliErrorConfiguration = {
Expand All @@ -121,6 +127,15 @@ export const cliErrorsConfig: Record<
CliConfigErrorCategory,
CliErrorConfiguration
> = {
// Usually when a manual build script has failed, or if an autodetected language
// was unintended to have CodeQL analysis run on it.
[CliConfigErrorCategory.DetectedCodeButCouldNotProcess]: {
henrymercer marked this conversation as resolved.
Show resolved Hide resolved
cliErrorMessageSnippets: [
henrymercer marked this conversation as resolved.
Show resolved Hide resolved
"CodeQL detected code written in",
"but could not process any of it",
],
additionalErrorMessageToPrepend: `Check the build script, if applicable, for the language specified in the error:`,
henrymercer marked this conversation as resolved.
Show resolved Hide resolved
},
// Version of CodeQL CLI is incompatible with this version of the CodeQL Action
[CliConfigErrorCategory.IncompatibleWithActionVersion]: {
cliErrorMessageSnippets: ["is not compatible with this CodeQL CLI"],
Expand All @@ -142,7 +157,8 @@ export const cliErrorsConfig: Record<
* `codeql database finalize`. To ensure users get a good error message, we detect this manually
* here, and upon detection override the error message.
*
* This can be removed once support for CodeQL 2.11.6 is removed.
* This can be removed once support for CodeQL 2.11.6 is removed, and once removed, exit code 32
* can be applied to the DetectedCodeButCouldNotProcess category.
*/
[CliConfigErrorCategory.NoJavaScriptTypeScriptCodeFound]: {
exitCode: 32,
angelapwen marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -151,6 +167,25 @@ export const cliErrorsConfig: Record<
"No code found during the build. Please see: " +
"https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build.",
},
[CliConfigErrorCategory.NoBuildCommandAutodetected]: {
cliErrorMessageSnippets: ["Could not auto-detect a suitable build method"],
},
[CliConfigErrorCategory.NoBuildMethodAutodetected]: {
cliErrorMessageSnippets: [
"Could not detect a suitable build command for the source checkout",
],
},
[CliConfigErrorCategory.NoSupportedBuildCommandSucceeded]: {
cliErrorMessageSnippets: ["No supported build command succeeded"],
},
[CliConfigErrorCategory.NoSupportedBuildSystemDetected]: {
cliErrorMessageSnippets: ["No supported build system detected"],
},
[CliConfigErrorCategory.NoSupportedLanguagesDetected]: {
cliErrorMessageSnippets: [
"CodeQL did not detect any code written in languages supported by CodeQL",
],
angelapwen marked this conversation as resolved.
Show resolved Hide resolved
},
};

// Check if the given CLI error or exit code, if applicable, apply to any known
Expand Down
4 changes: 3 additions & 1 deletion src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,9 @@ export async function getCodeQLForCmd(

if (
config.buildMode !== undefined &&
(await this.supportsFeature(ToolsFeature.BuildModeOption))
(await this.supportsFeature(
ToolsFeature.BuildModeOption as ToolsFeature,
angelapwen marked this conversation as resolved.
Show resolved Hide resolved
))
) {
extraArgs.push(`--build-mode=${config.buildMode}`);
}
Expand Down
Loading