Skip to content

Commit ae42f51

Browse files
committed
docs(README): complete docs for existing errors
1 parent 604d68a commit ae42f51

7 files changed

Lines changed: 118 additions & 36 deletions

File tree

README.md

Lines changed: 105 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,20 +1011,20 @@ try {
10111011
}
10121012
```
10131013

1014-
#### `GitHubProjectUnknownFieldError`
1014+
#### `GitHubProjectNotFoundError`
10151015

1016-
Thrown when a configured field configured in the `Project` constructor cannot be found in the project.
1016+
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.
10171017

10181018
```js
1019-
import Project, { GitHubProjectUnknownFieldError } from "github-project";
1019+
import Project, { GitHubProjectNotFoundError } from "github-project";
10201020

10211021
try {
10221022
await myScript(new Project(options));
10231023
} catch (error) {
1024-
if (error instanceof GitHubProjectUnknownFieldError) {
1025-
analytics.track("GitHubProjectUnknownFieldError", {
1026-
projectFieldNames: error.details.projectFieldNames,
1027-
userFieldName: error.details.userFieldName,
1024+
if (error instanceof GitHubProjectNotFoundError) {
1025+
analytics.track("GitHubProjectNotFoundError", {
1026+
owner: error.details.owner,
1027+
number: error.details.number,
10281028
});
10291029

10301030
myLogger.error(
@@ -1040,20 +1040,102 @@ try {
10401040
}
10411041
```
10421042

1043-
#### `GitHubProjectNotFoundError`
1043+
<table>
1044+
<thead align=left>
1045+
<tr>
1046+
<th>
1047+
name
1048+
</th>
1049+
<th>
1050+
type
1051+
</th>
1052+
<th width=100%>
1053+
description
1054+
</th>
1055+
</tr>
1056+
</thead>
1057+
<tbody align=left valign=top>
1058+
<tr>
1059+
<th>
1060+
<code>name</code>
1061+
</th>
1062+
<td>
1063+
<code>constant</code>
1064+
</td>
1065+
<td><code>GitHubProjectNotFoundError</code></td>
1066+
</tr>
1067+
<tr>
1068+
<th>
1069+
<code>message</code>
1070+
</th>
1071+
<td>
1072+
<code>constant</code>
1073+
</td>
1074+
<td>
10441075

1045-
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.
1076+
> Project cannot be found
1077+
1078+
</td>
1079+
<tr>
1080+
<th>
1081+
<code>details</code>
1082+
</th>
1083+
<td>
1084+
<code>object</code>
1085+
</td>
1086+
<td>
1087+
1088+
Object with error details
1089+
1090+
</td>
1091+
</tr>
1092+
<tr>
1093+
<th>
1094+
<code>details.owner</code>
1095+
</th>
1096+
<td>
1097+
<code>string</code>
1098+
</td>
1099+
<td>
1100+
1101+
Login of owner of the project
1102+
1103+
</td>
1104+
</tr>
1105+
<tr>
1106+
<th>
1107+
<code>details.number</code>
1108+
</th>
1109+
<td>
1110+
<code>number</code>
1111+
</td>
1112+
<td>
1113+
1114+
Number of the project
1115+
1116+
</td>
1117+
</tr>
1118+
</tbody>
1119+
</table>
1120+
1121+
Example for `error.toHumanMessage()`:
1122+
1123+
> Project #1 could not be found for @gr2m
1124+
1125+
#### `GitHubProjectUnknownFieldError`
1126+
1127+
Thrown when a configured field configured in the `Project` constructor cannot be found in the project.
10461128

10471129
```js
1048-
import Project, { GitHubProjectNotFoundError } from "github-project";
1130+
import Project, { GitHubProjectUnknownFieldError } from "github-project";
10491131

10501132
try {
10511133
await myScript(new Project(options));
10521134
} catch (error) {
1053-
if (error instanceof GitHubProjectNotFoundError) {
1054-
analytics.track("GitHubProjectNotFoundError", {
1055-
owner: error.details.owner,
1056-
number: error.details.number,
1135+
if (error instanceof GitHubProjectUnknownFieldError) {
1136+
analytics.track("GitHubProjectUnknownFieldError", {
1137+
projectFieldNames: error.details.projectFieldNames,
1138+
userFieldName: error.details.userFieldName,
10571139
});
10581140

10591141
myLogger.error(
@@ -1091,7 +1173,7 @@ try {
10911173
<td>
10921174
<code>constant</code>
10931175
</td>
1094-
<td><code>GitHubProjectNotFoundError</code></td>
1176+
<td><code>GitHubProjectUnknownFieldError</code></td>
10951177
</tr>
10961178
<tr>
10971179
<th>
@@ -1127,7 +1209,7 @@ Object with error details
11271209
</td>
11281210
<td>
11291211

1130-
Names of the fields in the project.
1212+
Names of all project fields as shown in the project
11311213

11321214
</td>
11331215
</tr>
@@ -1136,24 +1218,24 @@ Names of the fields in the project.
11361218
<code>details.userFieldName</code>
11371219
</th>
11381220
<td>
1139-
<code>string</code>
1221+
<code>object</code>
11401222
</td>
11411223
<td>
11421224

1143-
The stringified value set in the API call.
1225+
Name of the field provided by the user
11441226

11451227
</td>
11461228
</tr>
11471229
<tr>
11481230
<th>
1149-
<code>details.userInternalFieldName</code>
1231+
<code>details.userFieldNameAlias</code>
11501232
</th>
11511233
<td>
1152-
<code>string</code>
1234+
<code>object</code>
11531235
</td>
11541236
<td>
11551237

1156-
The user-provided alias for the field.
1238+
Alias of the field name provided by the user
11571239

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

11631245
Example for `error.toHumanMessage()`:
11641246

1165-
> "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}
1247+
> "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}
11661248
11671249
#### `GitHubProjectUnknownFieldOptionError`
11681250

@@ -1277,7 +1359,7 @@ Object with field details
12771359
</td>
12781360
<td>
12791361

1280-
The field name as shown in the project.
1362+
The field name as shown in the project
12811363

12821364
</td>
12831365
</tr>

api/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class GitHubProjectUnknownFieldError extends GitHubProjectError {
3434
const projectFieldNames = this.details.projectFieldNames
3535
.map((node) => `"${node.name}"`)
3636
.join(", ");
37-
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}`;
37+
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}`;
3838
}
3939
}
4040

api/lib/project-fields-nodes-to-fields-map.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function projectFieldsNodesToFieldsMap(state, project, nodes) {
6767
);
6868

6969
return Object.entries(project.fields).reduce(
70-
(acc, [userInternalFieldName, userFieldNameOrConfig]) => {
70+
(acc, [userFieldNameAlias, userFieldNameOrConfig]) => {
7171
let fieldOptional = false;
7272
let userFieldName = userFieldNameOrConfig;
7373
if (typeof userFieldNameOrConfig === "object") {
@@ -87,7 +87,7 @@ export function projectFieldsNodesToFieldsMap(state, project, nodes) {
8787
if (!fieldOptional) {
8888
throw new GitHubProjectUnknownFieldError({
8989
userFieldName,
90-
userInternalFieldName,
90+
userFieldNameAlias,
9191
projectFieldNames,
9292
});
9393
}
@@ -97,19 +97,19 @@ export function projectFieldsNodesToFieldsMap(state, project, nodes) {
9797
return acc;
9898
}
9999

100-
acc[userInternalFieldName] = {
100+
acc[userFieldNameAlias] = {
101101
id: node.id,
102102
name: node.name,
103103
dataType: node.dataType,
104104
userName: userFieldName,
105-
optional: userInternalFieldName in optionalFields,
105+
optional: userFieldNameAlias in optionalFields,
106106
existsInProject: true,
107107
};
108108

109109
// Settings is a JSON string. It contains view information such as column width.
110110
// If the field is of type "Single select", then the `options` property will be set.
111111
if (node.options) {
112-
acc[userInternalFieldName].optionsById = node.options.reduce(
112+
acc[userFieldNameAlias].optionsById = node.options.reduce(
113113
(acc, option) => {
114114
return {
115115
...acc,
@@ -118,7 +118,7 @@ export function projectFieldsNodesToFieldsMap(state, project, nodes) {
118118
},
119119
{}
120120
);
121-
acc[userInternalFieldName].optionsByValue = node.options.reduce(
121+
acc[userFieldNameAlias].optionsByValue = node.options.reduce(
122122
(acc, option) => {
123123
return {
124124
...acc,

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export declare class GitHubProjectNotFoundError<
327327
type GitHubProjectUnknownFieldErrorDetails = {
328328
projectFieldNames: string[];
329329
userFieldName: string;
330-
userInternalFieldName: string;
330+
userFieldNameAlias: string;
331331
};
332332

333333
export declare class GitHubProjectUnknownFieldError<

index.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ export function testGitHubProjectUnknownFieldError() {
673673
const details = {
674674
projectFieldNames: ["one", "two"],
675675
userFieldName: "Three",
676-
userInternalFieldName: "three",
676+
userFieldNameAlias: "three",
677677
};
678678
const error = new GitHubProjectUnknownFieldError(details);
679679

test/snapshots/recorded.test.js.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Generated by [AVA](https://avajs.dev).
3838
'Iteration',
3939
],
4040
userFieldName: 'NOPE',
41-
userInternalFieldName: 'nope',
41+
userFieldNameAlias: 'nope',
4242
},
4343
message: 'Project field cannot be found',
4444
},
@@ -998,7 +998,7 @@ Generated by [AVA](https://avajs.dev).
998998
'Iteration',
999999
],
10001000
userFieldName: 'Nope',
1001-
userInternalFieldName: 'nonExistingField',
1001+
userFieldNameAlias: 'nonExistingField',
10021002
},
10031003
message: 'Project field cannot be found',
10041004
}
@@ -7468,7 +7468,7 @@ Generated by [AVA](https://avajs.dev).
74687468
'Iteration',
74697469
],
74707470
userFieldName: 'Unknown',
7471-
userInternalFieldName: 'unknown',
7471+
userFieldNameAlias: 'unknown',
74727472
},
74737473
message: 'Project field cannot be found',
74747474
}
@@ -7528,7 +7528,7 @@ Generated by [AVA](https://avajs.dev).
75287528
'Iteration',
75297529
],
75307530
userFieldName: 'NOPE',
7531-
userInternalFieldName: 'nope',
7531+
userFieldNameAlias: 'nope',
75327532
},
75337533
message: 'Project field cannot be found',
75347534
}
-5 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)