From 9f629b7eeca5213383b45f16daf611077acae1a8 Mon Sep 17 00:00:00 2001 From: Lennart Date: Sun, 23 Oct 2022 10:47:30 +0200 Subject: [PATCH 1/3] Update gatsby-layout-loader.ts --- packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts b/packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts index 2f58b39bbaaa6..ed0587c046824 100644 --- a/packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts +++ b/packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts @@ -39,6 +39,7 @@ const gatsbyLayoutLoader: LoaderDefinition = async function ( id: ERROR_CODES.NonExistentFileNode, context: { resourcePath: this.resourcePath, + mdxPath, }, }) } @@ -249,6 +250,7 @@ const gatsbyLayoutLoader: LoaderDefinition = async function ( id: ERROR_CODES.InvalidAcornAST, context: { resourcePath: this.resourcePath, + mdxPath }, error, }) From 8f882d9d9a6bd7421859edb33d0abb1f1eb04a73 Mon Sep 17 00:00:00 2001 From: Lennart Date: Sun, 23 Oct 2022 10:50:47 +0200 Subject: [PATCH 2/3] Update error-utils.ts --- packages/gatsby-plugin-mdx/src/error-utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-plugin-mdx/src/error-utils.ts b/packages/gatsby-plugin-mdx/src/error-utils.ts index ca385a96c0abf..94f9c816508f8 100644 --- a/packages/gatsby-plugin-mdx/src/error-utils.ts +++ b/packages/gatsby-plugin-mdx/src/error-utils.ts @@ -9,7 +9,7 @@ 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`, @@ -22,7 +22,7 @@ export const ERROR_MAP = { }, [ERROR_CODES.InvalidAcornAST]: { text: (context: { resourcePath: string }): string => - `Invalid AST. Parsed source code did not return valid output. File:\n${context.resourcePath}`, + `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`, From e19b6a9c00d365e744e431517a27642e626e242f Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 24 Oct 2022 08:14:57 +0200 Subject: [PATCH 3/3] improve --- packages/gatsby-plugin-mdx/src/error-utils.ts | 12 ++++++++---- .../gatsby-plugin-mdx/src/gatsby-layout-loader.ts | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/gatsby-plugin-mdx/src/error-utils.ts b/packages/gatsby-plugin-mdx/src/error-utils.ts index 94f9c816508f8..e2cbda7cde5fb 100644 --- a/packages/gatsby-plugin-mdx/src/error-utils.ts +++ b/packages/gatsby-plugin-mdx/src/error-utils.ts @@ -15,14 +15,18 @@ export const ERROR_MAP = { 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.\n\nTemplate:\n${context.resourcePath}${context.mdxPath ? `\nFile: ${context.mdxPath}` : ``}`, + 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`, diff --git a/packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts b/packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts index ed0587c046824..c64a63d0d8dba 100644 --- a/packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts +++ b/packages/gatsby-plugin-mdx/src/gatsby-layout-loader.ts @@ -72,6 +72,7 @@ const gatsbyLayoutLoader: LoaderDefinition = async function ( id: ERROR_CODES.InvalidAcornAST, context: { resourcePath: this.resourcePath, + mdxPath, }, }) } @@ -250,7 +251,7 @@ const gatsbyLayoutLoader: LoaderDefinition = async function ( id: ERROR_CODES.InvalidAcornAST, context: { resourcePath: this.resourcePath, - mdxPath + mdxPath, }, error, })