From cffd02c48eae91688d6fe2f6fbbd7fde88db4956 Mon Sep 17 00:00:00 2001 From: Nick Cipollo Date: Thu, 2 Jan 2020 23:12:45 -0500 Subject: [PATCH] Add artifact upload error handling --- lib/ArtifactUploader.js | 16 +++++++++++++++- src/ArtifactUploader.ts | 16 +++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/ArtifactUploader.js b/lib/ArtifactUploader.js index 91dbdec..1c9ac01 100644 --- a/lib/ArtifactUploader.js +++ b/lib/ArtifactUploader.js @@ -8,7 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); +const core = __importStar(require("@actions/core")); class GithubArtifactUploader { constructor(releases) { this.releases = releases; @@ -16,7 +24,13 @@ class GithubArtifactUploader { uploadArtifacts(artifacts, uploadUrl) { return __awaiter(this, void 0, void 0, function* () { artifacts.forEach((artifact) => __awaiter(this, void 0, void 0, function* () { - yield this.releases.uploadArtifact(uploadUrl, artifact.contentLength, artifact.contentType, artifact.readFile(), artifact.name); + try { + yield this.releases.uploadArtifact(uploadUrl, artifact.contentLength, artifact.contentType, artifact.readFile(), artifact.name); + } + catch (error) { + const message = `Failed to upload artifact ${artifact.name}. Does it already exist?`; + core.warning(message); + } })); }); } diff --git a/src/ArtifactUploader.ts b/src/ArtifactUploader.ts index 2cb234b..dd6b676 100644 --- a/src/ArtifactUploader.ts +++ b/src/ArtifactUploader.ts @@ -1,3 +1,4 @@ +import * as core from '@actions/core'; import { Artifact } from "./Artifact"; import { Releases } from "./Releases"; @@ -14,11 +15,16 @@ export class GithubArtifactUploader implements ArtifactUploader { async uploadArtifacts(artifacts: Artifact[], uploadUrl: string) { artifacts.forEach(async artifact => { - await this.releases.uploadArtifact(uploadUrl, - artifact.contentLength, - artifact.contentType, - artifact.readFile(), - artifact.name) + try { + await this.releases.uploadArtifact(uploadUrl, + artifact.contentLength, + artifact.contentType, + artifact.readFile(), + artifact.name) + } catch(error) { + const message = `Failed to upload artifact ${artifact.name}. Does it already exist?` + core.warning(message) + } }); } } \ No newline at end of file