Consolidate error processing in actions

This commit is contained in:
daz
2024-04-11 10:18:07 -06:00
parent 1c25312b02
commit ba79f71e36
6 changed files with 42 additions and 52 deletions

View File

@@ -1,3 +1,5 @@
import * as core from '@actions/core'
export class PostActionJobFailure extends Error {
constructor(error: unknown) {
if (error instanceof Error) {
@@ -9,3 +11,31 @@ export class PostActionJobFailure extends Error {
}
}
}
export function handleMainActionError(error: unknown): void {
if (error instanceof AggregateError) {
core.setFailed(`Multiple errors returned`)
for (const err of error.errors) {
core.error(`Error ${error.errors.indexOf(err)}: ${err.message}`)
if (err.stack) {
core.info(err.stack)
}
}
} else {
core.setFailed(String(error))
if (error instanceof Error && error.stack) {
core.info(error.stack)
}
}
}
export function handlePostActionError(error: unknown): void {
if (error instanceof PostActionJobFailure) {
core.setFailed(String(error))
} else {
core.warning(`Unhandled error in Gradle post-action - job will continue: ${error}`)
if (error instanceof Error && error.stack) {
core.info(error.stack)
}
}
}