Skip to content

Commit

Permalink
Fix type error and explicitly type error map
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Mar 13, 2020
1 parent 4f7b7a3 commit bb22972
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/gatsby-cli/src/structured-errors/construct-error.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Joi from "@hapi/joi"
import stackTrace from "stack-trace"
import errorSchema from "./error-schema"
import { errorMap, defaultError, IErrorMapEntry } from "./error-map"
import { errorMap, defaultError, IErrorMapEntry, ErrorId } from "./error-map"
import { sanitizeStructuredStackTrace } from "../reporter/errors"

interface IConstructError {
details: {
id?: keyof typeof errorMap
id?: ErrorId
context?: Record<string, string>
error?: string
[key: string]: unknown
Expand Down
8 changes: 6 additions & 2 deletions packages/gatsby-cli/src/structured-errors/error-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const optionalGraphQLInfo = (context: IOptionalGraphQLInfoContext): string =>
context.plugin ? `\nPlugin: ${context.plugin}` : ``
}`

export const errorMap = {
const errors = {
"": {
text: (context): string => {
const sourceMessage = context.sourceMessage
Expand Down Expand Up @@ -430,7 +430,7 @@ export const errorMap = {
]
.filter(Boolean)
.join(`\n`),
level: `ERROR`,
level: Level.ERROR,
},
// node object didn't pass validation
"11467": {
Expand Down Expand Up @@ -486,6 +486,10 @@ export const errorMap = {
},
}

export type ErrorId = keyof typeof errors

export const errorMap: Record<ErrorId, IErrorMapEntry> = errors

export const defaultError = errorMap[``]

export interface IErrorMapEntry {
Expand Down

0 comments on commit bb22972

Please sign in to comment.