Skip to content

Commit dfde244

Browse files
committed
Include better error message
When users call init multiple times.
1 parent b31df3f commit dfde244

File tree

3 files changed

+55
-25
lines changed

3 files changed

+55
-25
lines changed

lib/init.js

+22-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/init.ts

+32-17
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,41 @@ export async function runInit(
9191
): Promise<TracerConfig | undefined> {
9292
fs.mkdirSync(config.dbLocation, { recursive: true });
9393

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}`
110124
);
125+
} else {
126+
throw e;
111127
}
112128
}
113-
114129
return await getCombinedTracerConfig(config, codeql);
115130
}
116131

0 commit comments

Comments
 (0)