Skip to content

Commit 3bcce67

Browse files
committed
Move config error processing for daatabase init
As we add more configuration errors, we can standardize throwing and catching them in the `codeql` file where we actually invoke the commands. Also, rename to `isCliConfigurationError` for more clarity.
1 parent d678f61 commit 3bcce67

9 files changed

Lines changed: 68 additions & 88 deletions

File tree

lib/cli-config-errors.js

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

lib/cli-config-errors.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/codeql.js

Lines changed: 25 additions & 11 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/init.js

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

lib/init.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/cli-config-errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const cliErrorsConfig: Record<
5151
* error: if there is an exit code, this takes precedence. Otherwise, matches
5252
* the error message against the expected message snippets.
5353
*/
54-
export function isConfigurationError(
54+
export function isCliConfigurationError(
5555
cliError: CliError,
5656
cliErrorMessage: string,
5757
exitCode?: number,

src/codeql.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import {
1212
isAnalyzingDefaultBranch,
1313
} from "./actions-util";
1414
import * as api from "./api-client";
15-
import {
16-
CliError,
17-
isConfigurationError as isCliConfigurationError,
18-
} from "./cli-config-errors";
15+
import { CliError, isCliConfigurationError } from "./cli-config-errors";
1916
import type { Config } from "./config-utils";
2017
import { EnvVar } from "./environment";
2118
import {
@@ -620,20 +617,40 @@ export async function getCodeQLForCmd(
620617
extraArgs.push("--no-sublanguage-file-coverage");
621618
}
622619

623-
await runTool(
624-
cmd,
625-
[
626-
"database",
627-
"init",
628-
"--db-cluster",
629-
config.dbLocation,
630-
`--source-root=${sourceRoot}`,
631-
...(await getLanguageAliasingArguments(this)),
632-
...extraArgs,
633-
...getExtraOptionsFromEnv(["database", "init"]),
634-
],
635-
{ stdin: externalRepositoryToken },
636-
);
620+
try {
621+
await runTool(
622+
cmd,
623+
[
624+
"database",
625+
"init",
626+
"--db-cluster",
627+
config.dbLocation,
628+
`--source-root=${sourceRoot}`,
629+
...(await getLanguageAliasingArguments(this)),
630+
...extraArgs,
631+
...getExtraOptionsFromEnv(["database", "init"]),
632+
],
633+
{ stdin: externalRepositoryToken },
634+
);
635+
} catch (e) {
636+
if (e instanceof CommandInvocationError) {
637+
if (isCliConfigurationError(CliError.InitCalledTwice, e.message)) {
638+
throw new util.UserError(
639+
`Is the "init" action called twice in the same job? ${e.message}`,
640+
);
641+
}
642+
if (
643+
isCliConfigurationError(
644+
CliError.IncompatibleWithActionVersion,
645+
e.message,
646+
) ||
647+
isCliConfigurationError(CliError.InvalidSourceRoot, e.message)
648+
) {
649+
throw new util.UserError(e.message);
650+
}
651+
}
652+
throw e;
653+
}
637654
},
638655
async runAutobuild(language: Language) {
639656
const autobuildCmd = path.join(

0 commit comments

Comments
 (0)