/
error-map.ts
570 lines (544 loc) · 21.6 KB
/
error-map.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
import { stripIndent, stripIndents } from "common-tags"
import { IOptionalGraphQLInfoContext, Level, Type } from "./types"
const optionalGraphQLInfo = (context: IOptionalGraphQLInfoContext): string =>
`${context.codeFrame ? `\n\n${context.codeFrame}` : ``}${
context.filePath ? `\n\nFile path: ${context.filePath}` : ``
}${context.urlPath ? `\nUrl path: ${context.urlPath}` : ``}${
context.plugin ? `\nPlugin: ${context.plugin}` : ``
}`
export enum ErrorCategory {
USER = `USER`,
SYSTEM = `SYSTEM`,
THIRD_PARTY = `THIRD_PARTY`,
}
const errors = {
"": {
text: (context): string => {
const sourceMessage = context.sourceMessage
? context.sourceMessage
: `There was an error`
return sourceMessage
},
level: Level.ERROR,
},
"95312": {
text: (context): string =>
`"${context.ref}" is not available during server side rendering.`,
level: Level.ERROR,
docsUrl: `https://gatsby.dev/debug-html`,
category: ErrorCategory.USER,
},
"95313": {
text: (context): string =>
`Building static HTML failed${
context.errorPath ? ` for path "${context.errorPath}"` : ``
}`,
level: Level.ERROR,
docsUrl: `https://gatsby.dev/debug-html`,
},
"98123": {
text: (context): string =>
`${context.stageLabel} failed\n\n${
context.sourceMessage ?? context.message
}`,
type: Type.WEBPACK,
level: Level.ERROR,
},
"98124": {
text: (context): string =>
`${context.stageLabel} failed\n\n${context.sourceMessage}\n\nIf you're trying to use a package make sure that '${context.packageName}' is installed. If you're trying to use a local file make sure that the path is correct.`,
type: Type.WEBPACK,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"85901": {
text: (context): string =>
stripIndent(`
There was an error in your GraphQL query:\n\n${
context.sourceMessage
}${optionalGraphQLInfo(context)}`),
type: Type.GRAPHQL,
level: Level.ERROR,
},
// Deprecated
"85907": {
text: (context): string =>
`There was an error in your GraphQL query:\n\n${context.message}`,
type: Type.GRAPHQL,
level: Level.ERROR,
},
"85908": {
text: (context): string => {
const closestFragment = context.closestFragment
? `\n\nDid you mean to use ` + `"${context.closestFragment}"?`
: ``
return `There was an error in your GraphQL query:\n\nThe fragment "${context.fragmentName}" does not exist.\n\n${context.codeFrame}${closestFragment}`
},
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
// Deprecated
"85909": {
text: (context): string => context.sourceMessage,
type: Type.GRAPHQL,
level: Level.ERROR,
},
"85910": {
text: (context): string =>
stripIndents(`
Multiple "root" queries found: "${context.name}" and "${context.otherName}".
Only the first ("${context.otherName}") will be registered.
Instead of:
${context.beforeCodeFrame}
Do:
${context.afterCodeFrame}
This can happen when you use two page/static queries in one file. Please combine those into one query.
If you're defining multiple components (each with a static query) in one file, you'll need to move each component to its own file.
`),
type: Type.GRAPHQL,
level: Level.ERROR,
docsUrl: `https://www.gatsbyjs.org/docs/graphql/`,
category: ErrorCategory.USER,
},
"85911": {
text: (context): string =>
stripIndent(`
There was a problem parsing "${context.filePath}"; any GraphQL
fragments or queries in this file were not processed.
This may indicate a syntax error in the code, or it may be a file type
that Gatsby does not know how to parse.
`),
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"85912": {
text: (context): string =>
`Failed to parse preprocessed file ${context.filePath}`,
type: Type.GRAPHQL,
level: Level.ERROR,
},
"85913": {
text: (context): string =>
`There was a problem reading the file: ${context.filePath}`,
type: Type.GRAPHQL,
level: Level.ERROR,
},
"85914": {
text: (context): string =>
`There was a problem reading the file: ${context.filePath}`,
type: Type.GRAPHQL,
level: Level.ERROR,
},
// default parsing error
"85915": {
text: (context): string =>
`There was a problem parsing the GraphQL query in file: ${context.filePath}`,
type: Type.GRAPHQL,
level: Level.ERROR,
},
"85916": {
text: (context): string =>
`String interpolation is not allowed in graphql tag:\n\n${context.codeFrame}`,
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"85917": {
text: (context): string =>
`Unexpected empty graphql tag${
context.codeFrame ? `\n\n${context.codeFrame}` : ``
}`,
type: Type.GRAPHQL,
level: Level.ERROR,
},
"85918": {
text: (context): string =>
stripIndent(`
GraphQL syntax error in query:\n\n${context.sourceMessage}${
context.codeFrame ? `\n\n${context.codeFrame}` : ``
}`),
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
// Duplicate fragment
"85919": {
text: (context): string =>
stripIndent(`
Found two different GraphQL fragments with identical name "${context.fragmentName}". Fragment names must be unique
File: ${context.leftFragment.filePath}
${context.leftFragment.codeFrame}
File: ${context.rightFragment.filePath}
${context.rightFragment.codeFrame}
`),
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
// Undefined variables in Queries
"85920": {
text: (context): string => {
const staticQueryMessage = stripIndents(`Suggestion 1:
If you're not using a page query but a useStaticQuery / StaticQuery you see this error because they currently don't support variables. To learn more about the limitations of useStaticQuery / StaticQuery, please visit these docs:
https://www.gatsbyjs.org/docs/use-static-query/
https://www.gatsbyjs.org/docs/static-query/`)
const generalMessage = stripIndents(`Suggestion 2:
You might have a typo in the variable name "${context.variableName}" or you didn't provide the variable via context to this page query. Have a look at the docs to learn how to add data to context:
https://www.gatsbyjs.org/docs/page-query/#how-to-add-query-variables-to-a-page-query`)
return stripIndent(`
There was an error in your GraphQL query:\n\n${
context.sourceMessage
}${optionalGraphQLInfo(
context
)}\n\n${staticQueryMessage}\n\n${generalMessage}`)
},
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"85921": {
text: (context): string =>
`There was an error in your GraphQL query:\n\n${context.sourceMessage}\n\nIf you're e.g. filtering for specific nodes make sure that you choose the correct field (that has the same type "${context.inputType}") or adjust the context variable to the type "${context.expectedType}".`,
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"85922": {
text: (context): string =>
`There was an error in your GraphQL query:
${context.sourceMessage}
This can happen if you e.g. accidentally added { } to the field "${context.fieldName}". If you didn't expect "${context.fieldName}" to be of type "${context.fieldType}" make sure that your input source and/or plugin is correct.
However, if you expect "value" to exist, the field might be accessible in another subfield. Please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have.
It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned
"dummy content". Visit our docs to learn how you can define the schema for "${context.type}":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions`,
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"85923": {
text: (context): string =>
`There was an error in your GraphQL query:\n\n${context.sourceMessage}\n\nIf you don't expect "${context.field}" to exist on the type "${context.type}" it is most likely a typo.\nHowever, if you expect "${context.field}" to exist there are a couple of solutions to common problems:\n\n- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server\n- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have\n- You want to optionally use your field "${context.field}" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add at least one entry with that field ("dummy content")\n\nIt is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "${context.type}":\nhttps://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions`,
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"85924": {
text: (context): string =>
`There was an error in your GraphQL query:\n\n${
context.sourceMessage
}\n\nThis can happen when you or a plugin/theme explicitly defined the GraphQL schema for this GraphQL object type via the schema customization API and "${
context.value
}" doesn't match the (scalar) type of "${
context.type
}".${optionalGraphQLInfo(context)}`,
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"85925": {
text: (context): string =>
`There was an error in your GraphQL query:\n\n${
context.sourceMessage
}\n\nThe field "${
context.field
}" was explicitly defined as non-nullable via the schema customization API (by yourself or a plugin/theme). This means that this field is not optional and you have to define a value. If this is not your desired behavior and you defined the schema yourself, go to "createTypes" in gatsby-node.js. If you're using a plugin/theme, you can learn more here on how to fix field types:\nhttps://www.gatsbyjs.org/docs/schema-customization/#fixing-field-types${optionalGraphQLInfo(
context
)}`,
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"85926": {
text: (context): string =>
`There was an error in your GraphQL query:\n\n${context.sourceMessage}\n\nThis can happen when you used graphql\`{ ...yourQuery }\` instead of graphql(\`{ ...yourQuery }\`) inside gatsby-node.js\n\nYou can't use the template literal function you're used to (from page queries) and rather have to call graphql() as a normal function.`,
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"85927": {
text: (context): string =>
`There was an error in your GraphQL query:\n\n${context.sourceMessage}\n\nSee if ${context.variable} has a typo or ${context.operation} doesn't actually require this variable.`,
type: Type.GRAPHQL,
level: Level.ERROR,
category: ErrorCategory.USER,
},
// Config errors
"10122": {
text: (context): string =>
`The site's gatsby-config.js failed validation:\n\n${context.sourceMessage}`,
type: Type.CONFIG,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"10123": {
text: (context): string =>
`We encountered an error while trying to load your site's ${context.configName}. Please fix the error and try again.`,
type: Type.CONFIG,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"10124": {
text: (context): string =>
`It looks like you were trying to add the config file? Please rename "${context.nearMatch}" to "${context.configName}.js"`,
type: Type.CONFIG,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"10125": {
text: (context): string =>
`Your ${context.configName} file is in the wrong place. You've placed it in the src/ directory. It must instead be at the root of your site next to your package.json file.`,
type: Type.CONFIG,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"10126": {
text: (context): string =>
`${context.path}/${context.configName} cannot export a function.` +
`\n\nA ${context.configName} exported as a Function can only be used as a theme and not run directly.` +
`\nIf you are trying to run a theme directly, use the theme in an example site or starter instead and run that site to test.` +
`\nIf you are in the root gatsby-config.js for your site, change the export to be an object and not a function as functions` +
`\nare not supported in the root gatsby-config.`,
type: Type.CONFIG,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"10226": {
text: (context): string =>
[
`Couldn't find the "${context.themeName}" plugin declared in "${context.configFilePath}".`,
context.pathToLocalTheme &&
`Tried looking for a local plugin in ${context.pathToLocalTheme}.`,
`Tried looking for an installed package in the following paths:\n${context.nodeResolutionPaths
.map(potentialLocationPath => ` - ${potentialLocationPath}`)
.join(`\n`)}`,
]
.filter(Boolean)
.join(`\n\n`),
type: Type.CONFIG,
level: Level.ERROR,
},
// Plugin errors
"11321": {
text: (context): string =>
`"${context.pluginName}" threw an error while running the ${
context.api
} lifecycle:\n\n${
context.sourceMessage ?? context.message
}${optionalGraphQLInfo(context)}`,
type: Type.PLUGIN,
level: Level.ERROR,
},
"11322": {
text: (context): string =>
`${
context.pluginName
} created a page and didn't pass the path to the component.\n\nThe page object passed to createPage:\n${JSON.stringify(
context.pageObject,
null,
4
)}\n\nSee the documentation for the "createPage" action — https://www.gatsbyjs.org/docs/actions/#createPage`,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"11323": {
text: (context): string =>
`${
context.pluginName
} must set the page path when creating a page.\n\nThe page object passed to createPage:\n${JSON.stringify(
context.pageObject,
null,
4
)}\n\nSee the documentation for the "createPage" action — https://www.gatsbyjs.org/docs/actions/#createPage`,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"11324": {
text: (context): string =>
`${context.message}\n\nSee the documentation for the "createPage" action — https://www.gatsbyjs.org/docs/actions/#createPage`,
level: Level.ERROR,
},
"11325": {
text: (context): string =>
`${
context.pluginName
} created a page with a component that doesn't exist.\n\nThe path to the missing component is "${
context.component
}"\n\nThe page object passed to createPage:\n${JSON.stringify(
context.pageObject,
null,
4
)}\n\nSee the documentation for the "createPage" action — https://www.gatsbyjs.org/docs/actions/#createPage`,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"11326": {
text: (context): string =>
`${
context.pluginName
} must set the absolute path to the page component when create creating a page.\n\nThe (relative) path you used for the component is "${
context.component
}"\n\nYou can convert a relative path to an absolute path by requiring the path module and calling path.resolve() e.g.\n\nconst path = require("path")\npath.resolve("${
context.component
}")\n\nThe page object passed to createPage:\n${JSON.stringify(
context.pageObject,
null,
4
)}\n\nSee the documentation for the "createPage" action — https://www.gatsbyjs.org/docs/actions/#createPage`,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"11327": {
text: (context): string =>
`You have an empty file in the "src/pages" directory at "${context.relativePath}". Please remove it or make it a valid component`,
level: Level.ERROR,
category: ErrorCategory.USER,
},
"11328": {
text: (context): string =>
`A page component must export a React component for it to be valid. Please make sure this file exports a React component:\n\n${context.fileName}`,
level: Level.ERROR,
category: ErrorCategory.USER,
},
// invalid or deprecated APIs
"11329": {
text: (context): string =>
[
stripIndent(`
Your plugins must export known APIs from their gatsby-${context.exportType}.js.
See https://www.gatsbyjs.org/docs/${context.exportType}-apis/ for the list of Gatsby ${context.exportType} APIs.
`),
]
.concat([``].concat(context.errors))
.concat(
context.fixes.length > 0
? [
``,
`Some of the following may help fix the error(s):`,
``,
...context.fixes.map(fix => `- ${fix}`),
]
: []
)
.join(`\n`),
level: Level.ERROR,
},
// "X" is not defined in Gatsby's node APIs
"11330": {
text: (context): string =>
`"${context.pluginName}" threw an error while running the ${
context.api
} lifecycle:\n\n${context.sourceMessage ?? context.message}\n\n${
context.codeFrame
}\n\nMake sure that you don't have a typo somewhere and use valid arguments in ${
context.api
} lifecycle.\nLearn more about ${
context.api
} here: https://www.gatsbyjs.org/docs/node-apis/#${context.api}`,
type: Type.PLUGIN,
level: Level.ERROR,
category: ErrorCategory.USER,
},
// Invalid plugin options
"11331": {
text: (context): string =>
[
stripIndent(`
Invalid plugin options for "${context.pluginName}"${
context.configDir ? `, configured by ${context.configDir}` : ``
}:
`),
]
.concat([``])
.concat(
context.validationErrors.map(error => `- ${error.message}`).join(`\n`)
)
.join(`\n`),
type: Type.PLUGIN,
level: Level.ERROR,
category: ErrorCategory.USER,
},
// node object didn't pass validation
"11467": {
text: (context): string =>
[
`The new node didn't pass validation: ${context.validationErrorMessage}`,
`Failing node:`,
JSON.stringify(context.node, null, 4),
`Note: there might be more nodes that failed validation. Output is limited to one node per type of validation failure to limit terminal spam.`,
context.codeFrame,
]
.filter(Boolean)
.join(`\n\n`),
level: Level.ERROR,
docsUrl: `https://www.gatsbyjs.org/docs/actions/#createNode`,
},
// local SSL certificate errors
"11521": {
text: (): string =>
`for custom ssl --https, --cert-file, and --key-file must be used together`,
level: Level.ERROR,
docsUrl: `https://www.gatsbyjs.org/docs/local-https/#custom-key-and-certificate-files`,
category: ErrorCategory.USER,
},
"11522": {
text: (): string => `Failed to generate dev SSL certificate`,
level: Level.ERROR,
docsUrl: `https://www.gatsbyjs.org/docs/local-https/#setup`,
},
// cli new command errors
"11610": {
text: (context): string =>
`It looks like you gave wrong argument orders . Try running instead "gatsby new ${context.starter} ${context.rootPath}"`,
level: Level.ERROR,
docsUrl: `https://www.gatsbyjs.org/docs/gatsby-cli/#new`,
category: ErrorCategory.USER,
},
"11611": {
text: (context): string =>
`It looks like you passed a URL to your project name. Try running instead "gatsby new new-gatsby-project ${context.rootPath}"`,
level: Level.ERROR,
docsUrl: `https://www.gatsbyjs.org/docs/gatsby-cli/#new`,
category: ErrorCategory.USER,
},
"11612": {
text: (context): string =>
`Could not create a project in "${context.path}" because it's not a valid path`,
level: Level.ERROR,
docsUrl: `https://www.gatsbyjs.org/docs/gatsby-cli/#new`,
category: ErrorCategory.USER,
},
"11613": {
text: (context): string =>
`Directory ${context.rootPath} is already an npm project`,
level: Level.ERROR,
docsUrl: `https://www.gatsbyjs.org/docs/gatsby-cli/#new`,
},
// Watchdog
"11701": {
text: (context): string =>
`Terminating the process (due to GATSBY_WATCHDOG_STUCK_STATUS_TIMEOUT):\n\nGatsby is in "${
context.status
}" state without any updates for ${(
context.stuckStatusWatchdogTimeoutDelay / 1000
).toFixed(
3
)} seconds. Activities preventing Gatsby from transitioning to idle state:\n\n${
context.stuckStatusDiagnosticMessage
}`,
level: Level.ERROR,
},
}
export type ErrorId = string | keyof typeof errors
export const errorMap: Record<ErrorId, IErrorMapEntry> = errors
export const defaultError = errorMap[``]
export interface IErrorMapEntry {
text: (context) => string
// keyof typeof is used for these enums so that the public facing API (e.g. used by setErrorMap) doesn't rely on enum but gives an union
level: keyof typeof Level
type?: keyof typeof Type
category?: keyof typeof ErrorCategory
docsUrl?: string
}