From e3c0d9b6cc4df97e2672a400ed8aed05322f1e97 Mon Sep 17 00:00:00 2001 From: Lukas Hennies <45569834+Gornoka@users.noreply.github.com> Date: Fri, 30 Jun 2023 12:09:04 +0200 Subject: [PATCH] Improved Error message for missing config file (#475) * error message for missing config * chore: formatting and index js * chore: update json5 * changes from cr Co-authored-by: AndreiLobanovich * chore: recreate dist.js * chore: revert package-lock * chore: newline fix --------- Co-authored-by: AndreiLobanovich --- .gitignore | 3 ++- dist/index.js | 11 ++++++++++- src/labeler.ts | 15 +++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 867d24a55..d7590431c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store node_modules/ -lib/ \ No newline at end of file +lib/ +.idea \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 28b173dd7..20509a5f1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -138,7 +138,16 @@ function getChangedFiles(client, prNumber) { } function getLabelGlobs(client, configurationPath) { return __awaiter(this, void 0, void 0, function* () { - const configurationContent = yield fetchContent(client, configurationPath); + let configurationContent; + try { + configurationContent = yield fetchContent(client, configurationPath); + } + catch (e) { + if (e.name == 'HttpError' || e.name == 'NotFound') { + core.warning(`The config file was not found at ${configurationPath}. Make sure it exists and that this action has the correct access rights.`); + } + throw e; + } // loads (hopefully) a `{[label:string]: string | StringOrMatchConfig[]}`, but is `any`: const configObject = yaml.load(configurationContent); // transform `any` => `Map` or throw if yaml is malformed: diff --git a/src/labeler.ts b/src/labeler.ts index 4aac4dd63..d1dc601f2 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -133,10 +133,17 @@ async function getLabelGlobs( client: ClientType, configurationPath: string ): Promise> { - const configurationContent: string = await fetchContent( - client, - configurationPath - ); + let configurationContent: string; + try { + configurationContent = await fetchContent(client, configurationPath); + } catch (e: any) { + if (e.name == 'HttpError' || e.name == 'NotFound') { + core.warning( + `The config file was not found at ${configurationPath}. Make sure it exists and that this action has the correct access rights.` + ); + } + throw e; + } // loads (hopefully) a `{[label:string]: string | StringOrMatchConfig[]}`, but is `any`: const configObject: any = yaml.load(configurationContent);