Skip to content

Commit

Permalink
fix(gatsby-plugin-mdx): Better AST error (#36866)
Browse files Browse the repository at this point in the history
  • Loading branch information
LekoArts committed Oct 24, 2022
1 parent 2b8c2f2 commit 58d5f2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/gatsby-plugin-mdx/src/error-utils.ts
Expand Up @@ -9,20 +9,24 @@ export const ERROR_CODES = {
export const ERROR_MAP = {
[ERROR_CODES.MdxCompilation]: {
text: (context: { absolutePath: string; errorMeta: any }): string =>
`Failed to compile the file "${context.absolutePath}". Original error message: \n\n${context.errorMeta.message}`,
`Failed to compile the file "${context.absolutePath}". Original error message:\n\n${context.errorMeta.message}`,
level: `ERROR`,
type: `PLUGIN`,
category: `USER`,
},
[ERROR_CODES.NonExistentFileNode]: {
text: (context: { resourcePath: string }): string =>
`Unable to locate the GraphQL File node for ${context.resourcePath}`,
text: (context: { resourcePath: string; mdxPath?: string }): string =>
`Unable to locate the GraphQL File node for ${context.resourcePath}${
context.mdxPath ? `\nFile: ${context.mdxPath}` : ``
}`,
level: `ERROR`,
type: `PLUGIN`,
},
[ERROR_CODES.InvalidAcornAST]: {
text: (context: { resourcePath: string }): string =>
`Invalid AST. Parsed source code did not return valid output. File:\n${context.resourcePath}`,
text: (context: { resourcePath: string; mdxPath?: string }): string =>
`Invalid AST. Parsed source code did not return valid output.\n\nTemplate:\n${
context.resourcePath
}${context.mdxPath ? `\nFile: ${context.mdxPath}` : ``}`,
level: `ERROR`,
type: `PLUGIN`,
category: `USER`,
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts
Expand Up @@ -39,6 +39,7 @@ const gatsbyLayoutLoader: LoaderDefinition = async function (
id: ERROR_CODES.NonExistentFileNode,
context: {
resourcePath: this.resourcePath,
mdxPath,
},
})
}
Expand Down Expand Up @@ -71,6 +72,7 @@ const gatsbyLayoutLoader: LoaderDefinition = async function (
id: ERROR_CODES.InvalidAcornAST,
context: {
resourcePath: this.resourcePath,
mdxPath,
},
})
}
Expand Down Expand Up @@ -249,6 +251,7 @@ const gatsbyLayoutLoader: LoaderDefinition = async function (
id: ERROR_CODES.InvalidAcornAST,
context: {
resourcePath: this.resourcePath,
mdxPath,
},
error,
})
Expand Down

0 comments on commit 58d5f2a

Please sign in to comment.