-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
GitHubProjectError
, GitHubProjectUnknownFieldError
, `GitHub…
…ProjectUnknownFieldOptionError`, `GitHubProjectUpdateReadOnlyFieldError` (#132) BREAKING CHANGE: When a field could not be found, the message on the thrown error looked like this > [github-project] "NOPE" could not be matched with any of the existing field names: "Title", "Assignees", "Status", "Labels", "Linked pull requests", "Reviewers", "Repository", "Milestone", "Text", "Number", "Date", "Single select", "Iteration". If the field should be considered optional, then set it to "nope: { name: "NOPE", optional: true} it is now > Project field cannot be found The original message can still be retrieved using `error.toHumanMessage()` BREAKING CHANGE: When a user value cannot be matched with a field option, the message on the thrown error looked like this > [github-project] "unknown" is an invalid option for "Single select" it is now > Project field option cannot be found The original message can still be retrieved using `error.toHumanMessage()` BREAKING CHANGE: if a user tried to update a read-only field, the message on the thrown error looked like this > [github-project] Cannot update read-only fields: "Assignees" (.assignees) it is now > Project read-only field cannot be updated --------- Co-authored-by: Tom Elliott <13594679+tmelliottjr@users.noreply.github.com>
- Loading branch information
1 parent
fe3a502
commit 9437ed7
Showing
12 changed files
with
831 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// @ts-check | ||
|
||
export class GitHubProjectError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = this.constructor.name; | ||
this.details = {}; | ||
} | ||
/* c8 ignore start */ | ||
toHumanMessage() { | ||
return this.message; | ||
} | ||
/* c8 ignore stop */ | ||
} | ||
|
||
export class GitHubProjectUnknownFieldError extends GitHubProjectError { | ||
constructor(details) { | ||
super("Project field cannot be found"); | ||
this.details = details; | ||
} | ||
|
||
toHumanMessage() { | ||
const projectFieldNames = this.details.projectFieldNames | ||
.map((node) => `"${node.name}"`) | ||
.join(", "); | ||
return `"${this.details.userFieldName}" could not be matched with any of the existing field names: ${projectFieldNames}. If the field should be considered optional, then set it to "${this.details.userInternalFieldName}: { name: "${this.details.userFieldName}", optional: true}`; | ||
} | ||
} | ||
|
||
export class GitHubProjectUnknownFieldOptionError extends GitHubProjectError { | ||
constructor(details) { | ||
super("Project field option cannot be found"); | ||
this.details = details; | ||
} | ||
|
||
toHumanMessage() { | ||
const existingOptionsString = this.details.field.options | ||
.map((option) => `"${option.name}"`) | ||
.join(", "); | ||
|
||
return `"${this.details.userValue}" is an invalid option for "${this.details.field.name}".\n\nKnown options are:\n${existingOptionsString}`; | ||
} | ||
} | ||
|
||
export class GitHubProjectUpdateReadOnlyFieldError extends GitHubProjectError { | ||
constructor(details) { | ||
super("Project read-only field cannot be updated"); | ||
this.details = details; | ||
} | ||
|
||
toHumanMessage() { | ||
return `Cannot update read-only fields: ${this.details.fields | ||
.map(({ userValue, userName }) => `"${userValue}" (.${userName})`) | ||
.join(", ")}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.