Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby-plugin-mdx): Better AST error #36866

Merged
merged 3 commits into from Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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