Skip to content

Commit 4a20f6e

Browse files
authored
Throw a better error if database doesn't exist due to language mismatch
1 parent bcf9535 commit 4a20f6e

8 files changed

Lines changed: 18 additions & 9 deletions

File tree

lib/codeql.js

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

lib/codeql.js.map

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

lib/download-database.js.map

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

lib/query.js

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

lib/query.js.map

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

src/codeql.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ libraryPathDependencies: codeql-${language}`
8282

8383
async function downloadDatabase(
8484
repoId: number,
85+
repoName: string,
8586
language: string,
8687
signedAuthToken?: string,
8788
pat?: string
@@ -101,8 +102,13 @@ async function downloadDatabase(
101102
);
102103
} catch (error: any) {
103104
console.log("Error while downloading database");
104-
if (error.httpStatusCode === 404) {
105-
throw new Error("No database available.");
105+
if (
106+
error.httpStatusCode === 404 &&
107+
error.httpMessage.includes("No database available for")
108+
) {
109+
throw new Error(
110+
`Language mismatch: The query targets ${language}, but the repository "${repoName}" has no CodeQL database available for that language.`
111+
);
106112
} else {
107113
throw error;
108114
}

src/download-database.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class HTTPError extends Error {
2121
this.httpMessage = httpMessage;
2222
}
2323
}
24+
2425
const userAgent = "actions/tool-cache";
2526

2627
/**

src/query.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ async function run(): Promise<void> {
4343
console.log("Getting database");
4444
const dbZip = await downloadDatabase(
4545
repo.id,
46+
repo.nwo,
4647
language,
4748
repo.token,
4849
repo.pat

0 commit comments

Comments
 (0)