Skip to content

Commit a76419a

Browse files
committed
Move wrapError and getErrorMessage out of util.ts
1 parent 071544a commit a76419a

3 files changed

Lines changed: 26 additions & 22 deletions

File tree

‎lib/entry-points.js‎

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

‎src/errors/index.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
import * as json from "../json";
22

3+
/**
4+
* If {@link error} is not already an instance of {@link Error}, then this function constructs
5+
* an {@link Error} with a string representation of {@link error} as the message.
6+
*/
7+
export function wrapError(error: unknown): Error {
8+
return error instanceof Error ? error : new Error(String(error));
9+
}
10+
11+
/**
12+
* Returns an appropriate message for the error.
13+
*
14+
* If the error is an {@link Error} instance, this returns the error message without
15+
* an `Error: ` prefix.
16+
*/
17+
export function getErrorMessage(error: unknown): string {
18+
return error instanceof Error ? error.message : String(error);
19+
}
20+
321
/**
422
* An Error class that indicates an error that occurred due to
523
* a misconfiguration of the action or the CodeQL CLI.

‎src/util.ts‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import {
2323
getEnv,
2424
type Env,
2525
} from "./environment";
26-
import { ConfigurationError } from "./errors";
26+
import { ConfigurationError, getErrorMessage, wrapError } from "./errors";
2727
import { Language } from "./languages";
2828
import { Logger } from "./logging";
2929

3030
// Re-export for backwards compatibility to avoid updating a lot of imports elsewhere.
31-
export { ConfigurationError, HTTPError, asHTTPError } from "./errors";
31+
export * from "./errors";
3232
export {
3333
getRequiredEnvParam,
3434
getOptionalEnvVar,
@@ -839,20 +839,6 @@ export function parseMatrixInput(
839839
}
840840
}
841841

842-
export function wrapError(error: unknown): Error {
843-
return error instanceof Error ? error : new Error(String(error));
844-
}
845-
846-
/**
847-
* Returns an appropriate message for the error.
848-
*
849-
* If the error is an `Error` instance, this returns the error message without
850-
* an `Error: ` prefix.
851-
*/
852-
export function getErrorMessage(error: unknown): string {
853-
return error instanceof Error ? error.message : String(error);
854-
}
855-
856842
export function prettyPrintPack(pack: Pack) {
857843
return `${pack.name}${pack.version ? `@${pack.version}` : ""}${
858844
pack.path ? `:${pack.path}` : ""

0 commit comments

Comments
 (0)