Avoid failing job on any failure in post-action

Failures to store cache entries should not fail the action or the Job.
This fix attempts to catch and log any unexpected errors that occur when
saving cache entries.

Fixes: #119
Fixes: #120
This commit is contained in:
Daz DeBoer 2021-11-15 09:21:55 -07:00
parent 4137be6a8b
commit 996094e8e8
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
3 changed files with 15 additions and 6 deletions

2
dist/post/index.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,15 +1,24 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import * as caches from './caches' import * as caches from './caches'
// 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))
// Invoked by GitHub Actions // Invoked by GitHub Actions
export async function run(): Promise<void> { export async function run(): Promise<void> {
try { try {
await caches.save() await caches.save()
} catch (error) { } catch (error) {
core.setFailed(String(error)) handleFailure(error)
if (error instanceof Error && error.stack) { }
core.info(error.stack) }
}
function handleFailure(error: unknown): void {
core.warning(`Unhandled error saving cache - job will continue: ${error}`)
if (error instanceof Error && error.stack) {
core.info(error.stack)
} }
} }