Skip to content

Commit 45693cc

Browse files
committed
Refactor ENOSPC check into isDiskConfigurationError function
1 parent c2fd8f5 commit 45693cc

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

lib/entry-points.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/codeql.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ test.beforeEach(() => {
5151
});
5252
});
5353

54+
test("isDiskConfigurationError - true for expected errors", async (t) => {
55+
t.true(
56+
codeql.isDiskConfigurationError(new Error("ENOSPC: Out of disk space")),
57+
);
58+
});
59+
60+
test("isDiskConfigurationError - false for other errors", async (t) => {
61+
t.false(codeql.isDiskConfigurationError("Not an Error instance"));
62+
63+
const otherMessages = [
64+
"Does not contain an error code we test for",
65+
"ENOSP: Not quite the full error code",
66+
];
67+
for (const otherMessage of otherMessages) {
68+
t.false(codeql.isDiskConfigurationError(new Error(otherMessage)));
69+
}
70+
});
71+
5472
async function installIntoToolcache({
5573
apiDetails = SAMPLE_DOTCOM_API_DETAILS,
5674
cliVersion,

src/codeql.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,21 @@ const GHES_MOST_RECENT_DEPRECATION_DATE = "2026-07-01";
273273
/** The CLI verbosity level to use for extraction in debug mode. */
274274
const EXTRACTION_DEBUG_MODE_VERBOSITY = "progress++";
275275

276+
/**
277+
* Decides whether `e` is a disk-related error outside of our control
278+
* that should be classified as a `ConfigurationError`.
279+
*
280+
* @param e The error to check.
281+
* @returns True if the error should be treated as a `ConfigurationError` or false if not.
282+
*/
283+
export function isDiskConfigurationError(e: unknown): boolean {
284+
if (!(e instanceof Error)) {
285+
return false;
286+
}
287+
288+
return e.message.includes("ENOSPC"); // out of disk space
289+
}
290+
276291
/**
277292
* Set up CodeQL CLI access.
278293
*
@@ -343,8 +358,7 @@ export async function setupCodeQL(
343358
} catch (rawError) {
344359
const e = api.wrapApiConfigurationError(rawError);
345360
const ErrorClass =
346-
e instanceof util.ConfigurationError ||
347-
(e instanceof Error && e.message.includes("ENOSPC")) // out of disk space
361+
e instanceof util.ConfigurationError || isDiskConfigurationError(e)
348362
? util.ConfigurationError
349363
: Error;
350364

0 commit comments

Comments
 (0)