@@ -91,26 +91,41 @@ export async function runInit(
91
91
) : Promise < TracerConfig | undefined > {
92
92
fs . mkdirSync ( config . dbLocation , { recursive : true } ) ;
93
93
94
- if ( await codeQlVersionAbove ( codeql , CODEQL_VERSION_NEW_TRACING ) ) {
95
- // Init a database cluster
96
- await codeql . databaseInitCluster (
97
- config . dbLocation ,
98
- config . languages ,
99
- sourceRoot ,
100
- processName ,
101
- processLevel
102
- ) ;
103
- } else {
104
- for ( const language of config . languages ) {
105
- // Init language database
106
- await codeql . databaseInit (
107
- util . getCodeQLDatabasePath ( config , language ) ,
108
- language ,
109
- sourceRoot
94
+ try {
95
+ if ( await codeQlVersionAbove ( codeql , CODEQL_VERSION_NEW_TRACING ) ) {
96
+ // Init a database cluster
97
+ await codeql . databaseInitCluster (
98
+ config . dbLocation ,
99
+ config . languages ,
100
+ sourceRoot ,
101
+ processName ,
102
+ processLevel
103
+ ) ;
104
+ } else {
105
+ for ( const language of config . languages ) {
106
+ // Init language database
107
+ await codeql . databaseInit (
108
+ util . getCodeQLDatabasePath ( config , language ) ,
109
+ language ,
110
+ sourceRoot
111
+ ) ;
112
+ }
113
+ }
114
+ } catch ( e ) {
115
+ // Handle the situation where init is called twice
116
+ // for the same database in the same job.
117
+ if (
118
+ e instanceof Error &&
119
+ e . message ?. includes ( "Refusing to create databases" ) &&
120
+ e . message . includes ( "exists and is not an empty directory." )
121
+ ) {
122
+ throw new Error (
123
+ `Is the "init" action called twice in the same job? ${ e . message } `
110
124
) ;
125
+ } else {
126
+ throw e ;
111
127
}
112
128
}
113
-
114
129
return await getCombinedTracerConfig ( config , codeql ) ;
115
130
}
116
131
0 commit comments