Skip to content

Commit

Permalink
Improved Error message for missing config file (#475)
Browse files Browse the repository at this point in the history
* error message for missing config

* chore: formatting and index js

* chore: update json5

* changes from cr

Co-authored-by: AndreiLobanovich <andreilobanovich@github.com>

* chore: recreate dist.js

* chore: revert package-lock

* chore: newline fix

---------

Co-authored-by: AndreiLobanovich <andreilobanovich@github.com>
  • Loading branch information
Gornoka and AndreiLobanovich committed Jun 30, 2023
1 parent 0967ca8 commit e3c0d9b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules/
lib/
lib/
.idea
11 changes: 10 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,StringOrMatchConfig[]>` or throw if yaml is malformed:
Expand Down
15 changes: 11 additions & 4 deletions src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,17 @@ async function getLabelGlobs(
client: ClientType,
configurationPath: string
): Promise<Map<string, StringOrMatchConfig[]>> {
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);
Expand Down

0 comments on commit e3c0d9b

Please sign in to comment.