Skip to content

Commit 0dabead

Browse files
authored
Merge pull request #876 from github/aeisenberg/multi-init
Include better error message
2 parents fdb92bb + 5e69ce8 commit 0dabead

File tree

4 files changed

+57
-27
lines changed

4 files changed

+57
-27
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## [UNRELEASED]
44

5-
No user facing changes.
5+
- Display a better error message when encountering a workflow that runs the `codeql-action/init` action multiple times. [#876](https://github.com/github/codeql-action/pull/876)
66

77
## 1.0.29 - 21 Jan 2022
88

@@ -15,7 +15,7 @@ No user facing changes.
1515

1616
## 1.0.27 - 11 Jan 2022
1717

18-
- The `analyze` and `upload-sarif` actions will now wait up to 2 minutes for processing to complete after they have uploaded the results so they can report any processing errors that occurred. This behavior can be disabled by setting the `wait-for-processing` action input to `"false"`.
18+
- The `analyze` and `upload-sarif` actions will now wait up to 2 minutes for processing to complete after they have uploaded the results so they can report any processing errors that occurred. This behavior can be disabled by setting the `wait-for-processing` action input to `"false"`. [#855](https://github.com/github/codeql-action/pull/855)
1919

2020
## 1.0.26 - 10 Dec 2021
2121

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)