Skip to content

Commit 520eff7

Browse files
committed
Fix flushDiagnostics not ensuring directories exist
1 parent f2412f8 commit 520eff7

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/diagnostics.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ test("addDiagnostic writes temporary diagnostics and flushDiagnostics moves them
8888
);
8989
});
9090

91-
// addDiagnostic
9291
t.is(existsSync.callCount, 1);
93-
t.is(mkdirSync.callCount, 1);
92+
t.is(mkdirSync.callCount, 2);
9493
t.is(writeFileSync.callCount, 1);
9594
t.is(writeFileSync.args[0].length, 2);
9695
t.is(writeFileSync.args[0][1], JSON.stringify(diagnostic));

‎src/diagnostics.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { Config } from "./config-utils";
77
import type { FileSystem } from "./fs";
88
import { Language } from "./languages";
99
import { getActionsLogger, type Logger } from "./logging";
10-
import { getCodeQLDatabasePath } from "./util";
10+
import { getCodeQLDatabasePath, getErrorMessage } from "./util";
1111

1212
/**
1313
* Known tags for diagnostics. There is currently only "internal-error",
@@ -304,6 +304,7 @@ export function flushDiagnostics(
304304
`Moving ${diagnosticsCount} diagnostic(s) to their respective databases.`,
305305
);
306306

307+
const failedFlushDiagnostics: TemporaryDiagnostic[] = [];
307308
for (const temporary of temporaryDiagnostics) {
308309
// If `temporary.language` is `undefined`, then we didn't have a `config` at the time that
309310
// `addNoLanguageDiagnostic` was called. In that case, we arbitrarily choose the first
@@ -315,11 +316,20 @@ export function flushDiagnostics(
315316
const filename = path.basename(temporary.path);
316317
const destination = path.join(directory, filename);
317318

318-
action.fs.renameSync(temporary.path, destination);
319+
try {
320+
action.fs.mkdirSync(directory, { recursive: true });
321+
action.fs.renameSync(temporary.path, destination);
322+
} catch (err) {
323+
action.logger.warning(
324+
`Failed to rename '${temporary.path}' to '${destination}': ${getErrorMessage(err)}`,
325+
);
326+
327+
failedFlushDiagnostics.push(temporary);
328+
}
319329
}
320330

321331
// Reset the temporary diagnostics arrays.
322-
temporaryDiagnostics = [];
332+
temporaryDiagnostics = failedFlushDiagnostics;
323333
}
324334

325335
/**

0 commit comments

Comments
 (0)