Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move config error processing for database 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.
  • Loading branch information
angelapwen committed Feb 6, 2024
commit b5dd04b9c32eb100c22797d309b67e7e1661744a
6 changes: 3 additions & 3 deletions lib/cli-config-errors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/cli-config-errors.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 25 additions & 11 deletions lib/codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

44 changes: 6 additions & 38 deletions lib/init.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/cli-config-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const cliErrorsConfig: Record<
* error: if there is an exit code, this takes precedence. Otherwise, matches
* the error message against the expected message snippets.
*/
export function isConfigurationError(
export function isCliConfigurationError(
cliError: CliError,
cliErrorMessage: string,
exitCode?: number,
Expand Down
53 changes: 35 additions & 18 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import {
isAnalyzingDefaultBranch,
} from "./actions-util";
import * as api from "./api-client";
import {
CliError,
isConfigurationError as isCliConfigurationError,
} from "./cli-config-errors";
import { CliError, isCliConfigurationError } from "./cli-config-errors";
import type { Config } from "./config-utils";
import { EnvVar } from "./environment";
import {
Expand Down Expand Up @@ -634,20 +631,40 @@ export async function getCodeQLForCmd(
extraArgs.push("--no-sublanguage-file-coverage");
}

await runTool(
cmd,
[
"database",
"init",
"--db-cluster",
config.dbLocation,
`--source-root=${sourceRoot}`,
...(await getLanguageAliasingArguments(this)),
...extraArgs,
...getExtraOptionsFromEnv(["database", "init"]),
],
{ stdin: externalRepositoryToken },
);
try {
await runTool(
cmd,
[
"database",
"init",
"--db-cluster",
config.dbLocation,
`--source-root=${sourceRoot}`,
...(await getLanguageAliasingArguments(this)),
...extraArgs,
...getExtraOptionsFromEnv(["database", "init"]),
],
{ stdin: externalRepositoryToken },
);
} catch (e) {
if (e instanceof CommandInvocationError) {
if (isCliConfigurationError(CliError.InitCalledTwice, e.message)) {
throw new util.UserError(
`Is the "init" action called twice in the same job? ${e.message}`,
);
}
if (
isCliConfigurationError(
CliError.IncompatibleWithActionVersion,
e.message,
) ||
isCliConfigurationError(CliError.InvalidSourceRoot, e.message)
) {
throw new util.UserError(e.message);
}
}
throw e;
}
},
async runAutobuild(language: Language) {
const autobuildCmd = path.join(
Expand Down
Loading