Test with error message descontruction
This commit is contained in:
12
src/index.ts
12
src/index.ts
@@ -27,14 +27,16 @@ const loadSecretsAction = async () => {
|
||||
// Load secrets
|
||||
await loadSecrets(shouldExportEnv);
|
||||
} catch (error) {
|
||||
// It's possible for the Error constructor to be modified to be anything
|
||||
// in JavaScript, so the following code accounts for this possibility.
|
||||
// https://kentcdodds.com/blog/get-a-catch-block-error-message-with-typescript
|
||||
let message = "Unknown Error";
|
||||
if (error instanceof Error) {
|
||||
message = error.message;
|
||||
} else {
|
||||
message = String(error);
|
||||
if (message === "Unknown Error" && error.cause instanceof Error) {
|
||||
message = error.cause.message;
|
||||
}
|
||||
} else if (error && typeof error === "object" && "message" in error && typeof (error as { message: unknown }).message === "string") {
|
||||
message = (error as { message: string }).message;
|
||||
} else if (error !== null && error !== undefined) {
|
||||
message = typeof error === "string" ? error : JSON.stringify(error);
|
||||
}
|
||||
core.setFailed(message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user