Skip to content

Commit

Permalink
docs(README): complete docs for existing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Oct 5, 2023
1 parent 604d68a commit ae42f51
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 36 deletions.
128 changes: 105 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1011,20 +1011,20 @@ try {
}
```

#### `GitHubProjectUnknownFieldError`
#### `GitHubProjectNotFoundError`

Thrown when a configured field configured in the `Project` constructor cannot be found in the project.
Thrown when a project cannot be found based on the `owner` and `number` passed to the `Project` constructor. The error is also thrown if the project exists but cannot be found based on authentication.

```js
import Project, { GitHubProjectUnknownFieldError } from "github-project";
import Project, { GitHubProjectNotFoundError } from "github-project";

try {
await myScript(new Project(options));
} catch (error) {
if (error instanceof GitHubProjectUnknownFieldError) {
analytics.track("GitHubProjectUnknownFieldError", {
projectFieldNames: error.details.projectFieldNames,
userFieldName: error.details.userFieldName,
if (error instanceof GitHubProjectNotFoundError) {
analytics.track("GitHubProjectNotFoundError", {
owner: error.details.owner,
number: error.details.number,
});

myLogger.error(
Expand All @@ -1040,20 +1040,102 @@ try {
}
```

#### `GitHubProjectNotFoundError`
<table>
<thead align=left>
<tr>
<th>
name
</th>
<th>
type
</th>
<th width=100%>
description
</th>
</tr>
</thead>
<tbody align=left valign=top>
<tr>
<th>
<code>name</code>
</th>
<td>
<code>constant</code>
</td>
<td><code>GitHubProjectNotFoundError</code></td>
</tr>
<tr>
<th>
<code>message</code>
</th>
<td>
<code>constant</code>
</td>
<td>

Thrown when a project cannot be found based on the `owner` and `number` passed to the `Project` constructor. The error is also thrown if the project exists but cannot be found based on authentication.
> Project cannot be found
</td>
<tr>
<th>
<code>details</code>
</th>
<td>
<code>object</code>
</td>
<td>

Object with error details

</td>
</tr>
<tr>
<th>
<code>details.owner</code>
</th>
<td>
<code>string</code>
</td>
<td>

Login of owner of the project

</td>
</tr>
<tr>
<th>
<code>details.number</code>
</th>
<td>
<code>number</code>
</td>
<td>

Number of the project

</td>
</tr>
</tbody>
</table>

Example for `error.toHumanMessage()`:

> Project #1 could not be found for @gr2m
#### `GitHubProjectUnknownFieldError`

Thrown when a configured field configured in the `Project` constructor cannot be found in the project.

```js
import Project, { GitHubProjectNotFoundError } from "github-project";
import Project, { GitHubProjectUnknownFieldError } from "github-project";

try {
await myScript(new Project(options));
} catch (error) {
if (error instanceof GitHubProjectNotFoundError) {
analytics.track("GitHubProjectNotFoundError", {
owner: error.details.owner,
number: error.details.number,
if (error instanceof GitHubProjectUnknownFieldError) {
analytics.track("GitHubProjectUnknownFieldError", {
projectFieldNames: error.details.projectFieldNames,
userFieldName: error.details.userFieldName,
});

myLogger.error(
Expand Down Expand Up @@ -1091,7 +1173,7 @@ try {
<td>
<code>constant</code>
</td>
<td><code>GitHubProjectNotFoundError</code></td>
<td><code>GitHubProjectUnknownFieldError</code></td>
</tr>
<tr>
<th>
Expand Down Expand Up @@ -1127,7 +1209,7 @@ Object with error details
</td>
<td>

Names of the fields in the project.
Names of all project fields as shown in the project

</td>
</tr>
Expand All @@ -1136,24 +1218,24 @@ Names of the fields in the project.
<code>details.userFieldName</code>
</th>
<td>
<code>string</code>
<code>object</code>
</td>
<td>

The stringified value set in the API call.
Name of the field provided by the user

</td>
</tr>
<tr>
<th>
<code>details.userInternalFieldName</code>
<code>details.userFieldNameAlias</code>
</th>
<td>
<code>string</code>
<code>object</code>
</td>
<td>

The user-provided alias for the field.
Alias of the field name provided by the user

</td>
</tr>
Expand All @@ -1162,7 +1244,7 @@ The user-provided alias for the field.

Example for `error.toHumanMessage()`:

> "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}
> "NOPE" could not be matched with any of the existing field names: "My text", "My number", "My Date". If the field should be considered optional, then set it to "nope: { name: "NOPE", optional: true}
#### `GitHubProjectUnknownFieldOptionError`

Expand Down Expand Up @@ -1277,7 +1359,7 @@ Object with field details
</td>
<td>

The field name as shown in the project.
The field name as shown in the project

</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion api/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class GitHubProjectUnknownFieldError extends GitHubProjectError {
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}`;
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.userFieldNameAlias}: { name: "${this.details.userFieldName}", optional: true}`;
}
}

Expand Down
12 changes: 6 additions & 6 deletions api/lib/project-fields-nodes-to-fields-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function projectFieldsNodesToFieldsMap(state, project, nodes) {
);

return Object.entries(project.fields).reduce(
(acc, [userInternalFieldName, userFieldNameOrConfig]) => {
(acc, [userFieldNameAlias, userFieldNameOrConfig]) => {
let fieldOptional = false;
let userFieldName = userFieldNameOrConfig;
if (typeof userFieldNameOrConfig === "object") {
Expand All @@ -87,7 +87,7 @@ export function projectFieldsNodesToFieldsMap(state, project, nodes) {
if (!fieldOptional) {
throw new GitHubProjectUnknownFieldError({
userFieldName,
userInternalFieldName,
userFieldNameAlias,
projectFieldNames,
});
}
Expand All @@ -97,19 +97,19 @@ export function projectFieldsNodesToFieldsMap(state, project, nodes) {
return acc;
}

acc[userInternalFieldName] = {
acc[userFieldNameAlias] = {
id: node.id,
name: node.name,
dataType: node.dataType,
userName: userFieldName,
optional: userInternalFieldName in optionalFields,
optional: userFieldNameAlias in optionalFields,
existsInProject: true,
};

// Settings is a JSON string. It contains view information such as column width.
// If the field is of type "Single select", then the `options` property will be set.
if (node.options) {
acc[userInternalFieldName].optionsById = node.options.reduce(
acc[userFieldNameAlias].optionsById = node.options.reduce(
(acc, option) => {
return {
...acc,
Expand All @@ -118,7 +118,7 @@ export function projectFieldsNodesToFieldsMap(state, project, nodes) {
},
{}
);
acc[userInternalFieldName].optionsByValue = node.options.reduce(
acc[userFieldNameAlias].optionsByValue = node.options.reduce(
(acc, option) => {
return {
...acc,
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export declare class GitHubProjectNotFoundError<
type GitHubProjectUnknownFieldErrorDetails = {
projectFieldNames: string[];
userFieldName: string;
userInternalFieldName: string;
userFieldNameAlias: string;
};

export declare class GitHubProjectUnknownFieldError<
Expand Down
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ export function testGitHubProjectUnknownFieldError() {
const details = {
projectFieldNames: ["one", "two"],
userFieldName: "Three",
userInternalFieldName: "three",
userFieldNameAlias: "three",
};
const error = new GitHubProjectUnknownFieldError(details);

Expand Down
8 changes: 4 additions & 4 deletions test/snapshots/recorded.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Generated by [AVA](https://avajs.dev).
'Iteration',
],
userFieldName: 'NOPE',
userInternalFieldName: 'nope',
userFieldNameAlias: 'nope',
},
message: 'Project field cannot be found',
},
Expand Down Expand Up @@ -998,7 +998,7 @@ Generated by [AVA](https://avajs.dev).
'Iteration',
],
userFieldName: 'Nope',
userInternalFieldName: 'nonExistingField',
userFieldNameAlias: 'nonExistingField',
},
message: 'Project field cannot be found',
}
Expand Down Expand Up @@ -7468,7 +7468,7 @@ Generated by [AVA](https://avajs.dev).
'Iteration',
],
userFieldName: 'Unknown',
userInternalFieldName: 'unknown',
userFieldNameAlias: 'unknown',
},
message: 'Project field cannot be found',
}
Expand Down Expand Up @@ -7528,7 +7528,7 @@ Generated by [AVA](https://avajs.dev).
'Iteration',
],
userFieldName: 'NOPE',
userInternalFieldName: 'nope',
userFieldNameAlias: 'nope',
},
message: 'Project field cannot be found',
}
Expand Down
Binary file modified test/snapshots/recorded.test.js.snap
Binary file not shown.

0 comments on commit ae42f51

Please sign in to comment.