@@ -117,24 +117,7 @@ export async function runInit(
117
117
}
118
118
}
119
119
} catch ( e ) {
120
- // Handle the situation where init is called twice
121
- // for the same database in the same job.
122
- if (
123
- e instanceof Error &&
124
- e . message ?. includes ( "Refusing to create databases" ) &&
125
- e . message . includes ( "exists and is not an empty directory." )
126
- ) {
127
- throw new util . UserError (
128
- `Is the "init" action called twice in the same job? ${ e . message } `
129
- ) ;
130
- } else if (
131
- e instanceof Error &&
132
- e . message ?. includes ( "is not compatible with this CodeQL CLI" )
133
- ) {
134
- throw new util . UserError ( e . message ) ;
135
- } else {
136
- throw e ;
137
- }
120
+ throw processError ( e ) ;
138
121
}
139
122
return await getCombinedTracerConfig (
140
123
config ,
@@ -144,6 +127,42 @@ export async function runInit(
144
127
) ;
145
128
}
146
129
130
+ /**
131
+ * Possibly convert this error into a UserError in order to avoid
132
+ * counting this error towards our internal error budget.
133
+ *
134
+ * @param e The error to possibly convert to a UserError.
135
+ *
136
+ * @returns A UserError if the error is a known error that can be
137
+ * attributed to the user, otherwise the original error.
138
+ */
139
+ function processError ( e : any ) : Error {
140
+ if ( ! ( e instanceof Error ) ) {
141
+ return e ;
142
+ }
143
+
144
+ if (
145
+ // Init action called twice
146
+ e . message ?. includes ( "Refusing to create databases" ) &&
147
+ e . message . includes ( "exists and is not an empty directory." )
148
+ ) {
149
+ return new util . UserError (
150
+ `Is the "init" action called twice in the same job? ${ e . message } `
151
+ ) ;
152
+ }
153
+
154
+ if (
155
+ // Version of CodeQL CLI is incompatible with this version of the CodeQL Action
156
+ e . message ?. includes ( "is not compatible with this CodeQL CLI" ) ||
157
+ // Expected source location for database creation does not exist
158
+ e . message ?. includes ( "Invalid source root" )
159
+ ) {
160
+ return new util . UserError ( e . message ) ;
161
+ }
162
+
163
+ return e ;
164
+ }
165
+
147
166
// Runs a powershell script to inject the tracer into a parent process
148
167
// so it can tracer future processes, hopefully including the build process.
149
168
// If processName is given then injects into the nearest parent process with
0 commit comments