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 8 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.

12 changes: 11 additions & 1 deletion lib/codeql.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/codeql.js.map

Large diffs are not rendered by default.

39 changes: 38 additions & 1 deletion src/cli-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,20 @@ 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 = {
// All of these snippets should be present to match to a specific CliConfigErrorCategory.
angelapwen marked this conversation as resolved.
Show resolved Hide resolved
cliErrorMessageSnippets: string[];
exitCode?: number;
// Error message to prepend for this type of CLI error.
Expand All @@ -121,6 +128,18 @@ 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
exitCode: 32,
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:
"No code found during the build. Please see: " +
"https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build.",
angelapwen 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 @@ -145,12 +164,30 @@ export const cliErrorsConfig: Record<
* This can be removed once support for CodeQL 2.11.6 is removed.
*/
[CliConfigErrorCategory.NoJavaScriptTypeScriptCodeFound]: {
exitCode: 32,
cliErrorMessageSnippets: ["No JavaScript or TypeScript code found."],
additionalErrorMessageToPrepend:
"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
11 changes: 10 additions & 1 deletion src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ const GHES_VERSION_MOST_RECENTLY_DEPRECATED = "3.7";
const GHES_MOST_RECENT_DEPRECATION_DATE = "2023-11-08";

/*
* Deprecated in favor of ToolsFeature.
*
* Versions of CodeQL that version-flag certain functionality in the Action.
* For convenience, please keep these in descending order. Once a version
* flag is older than the oldest supported version above, it may be removed.
Expand Down Expand Up @@ -670,7 +672,14 @@ export async function getCodeQLForCmd(
// When `DYLD_INSERT_LIBRARIES` is set in the environment for a step,
// the Actions runtime introduces its own workaround for SIP
// (https://github.com/actions/runner/pull/416).
await runTool(autobuildCmd);
try {
await runTool(autobuildCmd);
} catch (e) {
if (e instanceof Error) {
throw wrapCliConfigurationError(e);
}
throw e;
}
},
async extractScannedLanguage(config: Config, language: Language) {
await runTool(cmd, [
Expand Down
Loading