Skip to content

Commit d97b342

Browse files
authored
Merge pull request #4098 from github/mbg/permission-error-as-configuration-error
Make `EACCES` when installing CodeQL CLI a `ConfigurationError`
2 parents c2fd8f5 + 47fa622 commit d97b342

3 files changed

Lines changed: 57 additions & 3 deletions

File tree

lib/entry-points.js

Lines changed: 11 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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,31 @@ 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+
t.true(
59+
codeql.isDiskConfigurationError(
60+
new Error(
61+
"EACCES: permission denied, mkdir /opt/hostedtoolcache/CodeQL/",
62+
),
63+
),
64+
);
65+
});
66+
67+
test("isDiskConfigurationError - false for other errors", async (t) => {
68+
t.false(codeql.isDiskConfigurationError("Not an Error instance"));
69+
70+
const otherMessages = [
71+
"Does not contain an error code we test for",
72+
"ENOSP: Not quite the full error code",
73+
];
74+
for (const otherMessage of otherMessages) {
75+
t.false(codeql.isDiskConfigurationError(new Error(otherMessage)));
76+
}
77+
});
78+
5479
async function installIntoToolcache({
5580
apiDetails = SAMPLE_DOTCOM_API_DETAILS,
5681
cliVersion,

src/codeql.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,26 @@ 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 (
289+
// out of disk space
290+
e.message.includes("ENOSPC") ||
291+
// access denied
292+
e.message.includes("EACCES")
293+
);
294+
}
295+
276296
/**
277297
* Set up CodeQL CLI access.
278298
*
@@ -343,8 +363,7 @@ export async function setupCodeQL(
343363
} catch (rawError) {
344364
const e = api.wrapApiConfigurationError(rawError);
345365
const ErrorClass =
346-
e instanceof util.ConfigurationError ||
347-
(e instanceof Error && e.message.includes("ENOSPC")) // out of disk space
366+
e instanceof util.ConfigurationError || isDiskConfigurationError(e)
348367
? util.ConfigurationError
349368
: Error;
350369

0 commit comments

Comments
 (0)