diff --git a/lib/entry-points.js b/lib/entry-points.js index 89234fdf3..c79607d1c 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -169556,6 +169556,12 @@ function checkSchema(schema, obj, options = {}, path30 = "") { } // src/errors/index.ts +function wrapError(error3) { + return error3 instanceof Error ? error3 : new Error(String(error3)); +} +function getErrorMessage(error3) { + return error3 instanceof Error ? error3.message : String(error3); +} var ConfigurationError = class extends Error { }; var HTTPError = class extends Error { @@ -169983,12 +169989,6 @@ function parseMatrixInput(matrixInput) { ); } } -function wrapError(error3) { - return error3 instanceof Error ? error3 : new Error(String(error3)); -} -function getErrorMessage(error3) { - return error3 instanceof Error ? error3.message : String(error3); -} function prettyPrintPack(pack) { return `${pack.name}${pack.version ? `@${pack.version}` : ""}${pack.path ? `:${pack.path}` : ""}`; } diff --git a/src/errors/index.ts b/src/errors/index.ts index a8887c8ea..b1281f3af 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -1,5 +1,23 @@ import * as json from "../json"; +/** + * If {@link error} is not already an instance of {@link Error}, then this function constructs + * an {@link Error} with a string representation of {@link error} as the message. + */ +export function wrapError(error: unknown): Error { + return error instanceof Error ? error : new Error(String(error)); +} + +/** + * Returns an appropriate message for the error. + * + * If the error is an {@link Error} instance, this returns the error message without + * an `Error: ` prefix. + */ +export function getErrorMessage(error: unknown): string { + return error instanceof Error ? error.message : String(error); +} + /** * An Error class that indicates an error that occurred due to * a misconfiguration of the action or the CodeQL CLI. diff --git a/src/util.ts b/src/util.ts index bff332ba3..8761cacb2 100644 --- a/src/util.ts +++ b/src/util.ts @@ -23,12 +23,12 @@ import { getEnv, type Env, } from "./environment"; -import { ConfigurationError } from "./errors"; +import { ConfigurationError, getErrorMessage, wrapError } from "./errors"; import { Language } from "./languages"; import { Logger } from "./logging"; // Re-export for backwards compatibility to avoid updating a lot of imports elsewhere. -export { ConfigurationError, HTTPError, asHTTPError } from "./errors"; +export * from "./errors"; export { getRequiredEnvParam, getOptionalEnvVar, @@ -839,20 +839,6 @@ export function parseMatrixInput( } } -export function wrapError(error: unknown): Error { - return error instanceof Error ? error : new Error(String(error)); -} - -/** - * Returns an appropriate message for the error. - * - * If the error is an `Error` instance, this returns the error message without - * an `Error: ` prefix. - */ -export function getErrorMessage(error: unknown): string { - return error instanceof Error ? error.message : String(error); -} - export function prettyPrintPack(pack: Pack) { return `${pack.name}${pack.version ? `@${pack.version}` : ""}${ pack.path ? `:${pack.path}` : ""