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,5 +1,3 @@
import * as core from '@actions/core'
import * as setupGradle from '../setup-gradle'
import * as gradle from '../execution/gradle'
import * as dependencyGraph from '../dependency-graph'
@@ -14,6 +12,7 @@ import {
setActionId
} from '../configuration'
import {saveDeprecationState} from '../deprecation-collector'
import {handleMainActionError} from '../errors'
/**
* The main entry point for the action, called by Github Actions for the step.
@@ -56,10 +55,7 @@ export async function run(): Promise<void> {
saveDeprecationState()
} catch (error) {
core.setFailed(String(error))
if (error instanceof Error && error.stack) {
core.info(error.stack)
}
handleMainActionError(error)
}
// Explicit process.exit() to prevent waiting for hanging promises.

View File

@@ -1,13 +1,12 @@
import * as core from '@actions/core'
import * as setupGradle from '../setup-gradle'
import {CacheConfig, SummaryConfig} from '../configuration'
import {PostActionJobFailure} from '../errors'
import {handlePostActionError} from '../errors'
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
// throw an uncaught exception. Instead of failing this action, just warn.
process.on('uncaughtException', e => handleFailure(e))
process.on('uncaughtException', e => handlePostActionError(e))
/**
* The post-execution entry point for the action, called by Github Actions after completing all steps for the Job.
@@ -16,22 +15,11 @@ export async function run(): Promise<void> {
try {
await setupGradle.complete(new CacheConfig(), new SummaryConfig())
} catch (error) {
if (error instanceof PostActionJobFailure) {
core.setFailed(String(error))
} else {
handleFailure(error)
}
handlePostActionError(error)
}
// Explicit process.exit() to prevent waiting for promises left hanging by `@actions/cache` on save.
process.exit()
}
function handleFailure(error: unknown): void {
core.warning(`Unhandled error in Gradle post-action - job will continue: ${error}`)
if (error instanceof Error && error.stack) {
core.info(error.stack)
}
}
run()