Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 73ba197

Browse files
committedApr 11, 2024
Check that the database exists before writing diagnostics to it
1 parent dd031bb commit 73ba197

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed
 

‎lib/diagnostics.js

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

‎lib/diagnostics.js.map

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

‎src/diagnostics.ts

+20-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mkdirSync, writeFileSync } from "fs";
1+
import { existsSync, mkdirSync, writeFileSync } from "fs";
22
import path from "path";
33

44
import { Config } from "./config-utils";
@@ -87,23 +87,31 @@ export function addDiagnostic(
8787
diagnostic: DiagnosticMessage,
8888
) {
8989
const logger = getActionsLogger();
90+
const databasePath = getCodeQLDatabasePath(config, language);
9091
const diagnosticsPath = path.resolve(
91-
getCodeQLDatabasePath(config, language),
92+
databasePath,
9293
"diagnostic",
9394
"codeql-action",
9495
);
9596

96-
try {
97-
// Create the directory if it doesn't exist yet.
98-
mkdirSync(diagnosticsPath, { recursive: true });
97+
// Check that the database exists before writing to it.
98+
if (existsSync(databasePath)) {
99+
try {
100+
// Create the directory if it doesn't exist yet.
101+
mkdirSync(diagnosticsPath, { recursive: true });
99102

100-
const jsonPath = path.resolve(
101-
diagnosticsPath,
102-
`codeql-action-${diagnostic.timestamp}.json`,
103-
);
103+
const jsonPath = path.resolve(
104+
diagnosticsPath,
105+
`codeql-action-${diagnostic.timestamp}.json`,
106+
);
104107

105-
writeFileSync(jsonPath, JSON.stringify(diagnostic));
106-
} catch (err) {
107-
logger.warning(`Unable to write diagnostic message to database: ${err}`);
108+
writeFileSync(jsonPath, JSON.stringify(diagnostic));
109+
} catch (err) {
110+
logger.warning(`Unable to write diagnostic message to database: ${err}`);
111+
}
112+
} else {
113+
logger.info(
114+
`Writing a diagnostic for ${language}, but the database at ${databasePath} does not exist yet.`,
115+
);
108116
}
109117
}

0 commit comments

Comments
 (0)
Please sign in to comment.