Check that the database exists before writing diagnostics to it
This commit is contained in:
parent
96f44cb9d2
commit
d4e7b0e493
3 changed files with 36 additions and 21 deletions
23
lib/diagnostics.js
generated
23
lib/diagnostics.js
generated
|
|
@ -32,15 +32,22 @@ exports.makeDiagnostic = makeDiagnostic;
|
|||
*/
|
||||
function addDiagnostic(config, language, diagnostic) {
|
||||
const logger = (0, logging_1.getActionsLogger)();
|
||||
const diagnosticsPath = path_1.default.resolve((0, util_1.getCodeQLDatabasePath)(config, language), "diagnostic", "codeql-action");
|
||||
try {
|
||||
// Create the directory if it doesn't exist yet.
|
||||
(0, fs_1.mkdirSync)(diagnosticsPath, { recursive: true });
|
||||
const jsonPath = path_1.default.resolve(diagnosticsPath, `codeql-action-${diagnostic.timestamp}.json`);
|
||||
(0, fs_1.writeFileSync)(jsonPath, JSON.stringify(diagnostic));
|
||||
const databasePath = (0, util_1.getCodeQLDatabasePath)(config, language);
|
||||
const diagnosticsPath = path_1.default.resolve(databasePath, "diagnostic", "codeql-action");
|
||||
// Check that the database exists before writing to it.
|
||||
if ((0, fs_1.existsSync)(databasePath)) {
|
||||
try {
|
||||
// Create the directory if it doesn't exist yet.
|
||||
(0, fs_1.mkdirSync)(diagnosticsPath, { recursive: true });
|
||||
const jsonPath = path_1.default.resolve(diagnosticsPath, `codeql-action-${diagnostic.timestamp}.json`);
|
||||
(0, fs_1.writeFileSync)(jsonPath, JSON.stringify(diagnostic));
|
||||
}
|
||||
catch (err) {
|
||||
logger.warning(`Unable to write diagnostic message to database: ${err}`);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
logger.warning(`Unable to write diagnostic message to database: ${err}`);
|
||||
else {
|
||||
logger.info(`Writing a diagnostic for ${language}, but the database at ${databasePath} does not exist yet.`);
|
||||
}
|
||||
}
|
||||
exports.addDiagnostic = addDiagnostic;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue