Refactor configuration errors (#2105)

Refactor the existing classes of configuration errors into their own file; consolidate the place we check for configuration errors into `codeql.ts`, where the actual command invocations happen.

Also, rename the `UserError` type to `ConfigurationError` to standardize on a single term.
This commit is contained in:
Angela P Wen
2024-02-08 09:20:03 -08:00
committed by GitHub
parent fc9f9e5ef9
commit 1515e2bb20
54 changed files with 654 additions and 502 deletions

View File

@@ -11,7 +11,7 @@ import {
doesDirectoryExist,
getCodeQLDatabasePath,
getRequiredEnvParam,
UserError,
ConfigurationError,
} from "./util";
// eslint-disable-next-line import/no-commonjs
@@ -26,7 +26,7 @@ const pkg = require("../package.json") as JSONSchemaForNPMPackageJsonFiles;
export const getRequiredInput = function (name: string): string {
const value = core.getInput(name);
if (!value) {
throw new UserError(`Input required and not supplied: ${name}`);
throw new ConfigurationError(`Input required and not supplied: ${name}`);
}
return value;
};
@@ -187,7 +187,7 @@ export async function getRef(): Promise<string> {
const hasShaInput = !!shaInput;
// If one of 'ref' or 'sha' are provided, both are required
if ((hasRefInput || hasShaInput) && !(hasRefInput && hasShaInput)) {
throw new UserError(
throw new ConfigurationError(
"Both 'ref' and 'sha' are required if one of them is provided.",
);
}