@@ -8,16 +8,17 @@ export enum CliError {
8
8
9
9
/**
10
10
* 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.
15
12
*/
16
13
export const cliErrorsConfig : Record <
17
14
CliError ,
18
15
{
19
16
cliErrorMessageSnippets : string [ ] ;
20
17
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 ;
21
22
}
22
23
> = {
23
24
// Version of CodeQL CLI is incompatible with this version of the CodeQL Action
@@ -29,6 +30,8 @@ export const cliErrorsConfig: Record<
29
30
"Refusing to create databases" ,
30
31
"exists and is not an empty directory" ,
31
32
] ,
33
+ actionErrorMessage : `Is the "init" action called twice in the same job?` ,
34
+ appendCliErrorToActionError : true ,
32
35
} ,
33
36
// Expected source location for database creation does not exist
34
37
[ CliError . InvalidSourceRoot ] : {
@@ -45,6 +48,10 @@ export const cliErrorsConfig: Record<
45
48
[ CliError . NoJavaScriptTypeScriptCodeFound ] : {
46
49
exitCode : 32 ,
47
50
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 ,
48
55
} ,
49
56
} ;
50
57
@@ -77,45 +84,25 @@ export function isCliConfigurationError(
77
84
}
78
85
79
86
/**
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`.
86
91
*/
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
-
109
92
export function processCliConfigurationError (
110
93
cliError : CliError ,
111
94
cliErrorMessage : string ,
112
95
) : 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
+ ) {
115
101
return cliErrorMessage ;
116
102
}
117
103
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 ;
121
108
}
0 commit comments