Skip to content

Commit c5a7e3e

Browse files
committed
Combine action error text into original configuration Record
1 parent 253c29f commit c5a7e3e

File tree

3 files changed

+43
-67
lines changed

3 files changed

+43
-67
lines changed

lib/cli-config-errors.js

Lines changed: 18 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/cli-config-errors.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli-config-errors.ts

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ export enum CliError {
88

99
/**
1010
* All of our caught CLI error messages that we handle specially: ie. if we
11-
* would like to categorize an error as a configuration error or not. Optionally
12-
* associated with a CLI error code as well. Note that either of the conditions
13-
* is enough to be considered a match: if the exit code is a match, or the error
14-
* messages match.
11+
* would like to categorize an error as a configuration error or not.
1512
*/
1613
export const cliErrorsConfig: Record<
1714
CliError,
1815
{
1916
cliErrorMessageSnippets: string[];
2017
exitCode?: number;
18+
// Error message to return in the action for this type of CLI error. If undefined, uses original CLI error message.
19+
actionErrorMessage?: string;
20+
// Whether to append the original CLI error to action error message. Default: true
21+
appendCliErrorToActionError?: boolean;
2122
}
2223
> = {
2324
// Version of CodeQL CLI is incompatible with this version of the CodeQL Action
@@ -29,6 +30,8 @@ export const cliErrorsConfig: Record<
2930
"Refusing to create databases",
3031
"exists and is not an empty directory",
3132
],
33+
actionErrorMessage: `Is the "init" action called twice in the same job?`,
34+
appendCliErrorToActionError: true,
3235
},
3336
// Expected source location for database creation does not exist
3437
[CliError.InvalidSourceRoot]: {
@@ -45,6 +48,10 @@ export const cliErrorsConfig: Record<
4548
[CliError.NoJavaScriptTypeScriptCodeFound]: {
4649
exitCode: 32,
4750
cliErrorMessageSnippets: ["No JavaScript or TypeScript code found."],
51+
actionErrorMessage:
52+
"No code found during the build. Please see: " +
53+
"https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build",
54+
appendCliErrorToActionError: false,
4855
},
4956
};
5057

@@ -77,45 +84,25 @@ export function isCliConfigurationError(
7784
}
7885

7986
/**
80-
* Maps a CLI error class to the error message that the Action should return in
81-
* case of this error. Leave undefined if the CLI error message should be returned
82-
* directly.
83-
*
84-
* Otherwise, specify an error message to return for this CLI error; and whether the
85-
* original CLI error text should be appended to it.
87+
* Returns the error message that the Action should return in case of this CLI error. If no
88+
* `actionErrorMessage` was defined, return the original CLI error. Otherwise, return the
89+
* `actionErrorMessage` with the CLI error message appended, depending on the value of
90+
* `appendCliErrorToActionError` in `cliErrorsConfig`.
8691
*/
87-
export const cliToActionErrorsConfig: Record<
88-
CliError,
89-
| {
90-
actionErrorMessage: string;
91-
appendCliError: boolean;
92-
}
93-
| undefined
94-
> = {
95-
[CliError.InitCalledTwice]: {
96-
actionErrorMessage: `Is the "init" action called twice in the same job?`,
97-
appendCliError: true,
98-
},
99-
[CliError.NoJavaScriptTypeScriptCodeFound]: {
100-
actionErrorMessage:
101-
"No code found during the build. Please see: " +
102-
"https://gh.io/troubleshooting-code-scanning/no-source-code-seen-during-build",
103-
appendCliError: false,
104-
},
105-
[CliError.IncompatibleWithActionVersion]: undefined,
106-
[CliError.InvalidSourceRoot]: undefined,
107-
};
108-
10992
export function processCliConfigurationError(
11093
cliError: CliError,
11194
cliErrorMessage: string,
11295
): string {
113-
const cliToActionErrorConfig = cliToActionErrorsConfig[cliError];
114-
if (cliToActionErrorConfig === undefined) {
96+
const cliErrorConfig = cliErrorsConfig[cliError];
97+
if (
98+
cliErrorConfig === undefined ||
99+
cliErrorConfig.actionErrorMessage === undefined
100+
) {
115101
return cliErrorMessage;
116102
}
117103

118-
return cliToActionErrorConfig.appendCliError
119-
? cliToActionErrorConfig.actionErrorMessage + cliErrorMessage
120-
: cliToActionErrorConfig.actionErrorMessage;
104+
// Append the CLI error message by default.
105+
return cliErrorConfig.appendCliErrorToActionError === false
106+
? cliErrorConfig.actionErrorMessage
107+
: cliErrorConfig.actionErrorMessage + cliErrorMessage;
121108
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy