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(mdx-loader): loader error message should display stacktrace if no extra MDX details #9091

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/docusaurus-mdx-loader/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,21 @@ export async function mdxLoader(
result = await processor.process({content, filePath});
} catch (errorUnknown) {
const error = errorUnknown as Error;

// MDX can emit errors that have useful extra attributes
const errorJSON = JSON.stringify(error, null, 2);
const errorDetails =
errorJSON === '{}'
? // regular JS error case: print stacktrace
error.stack ?? 'N/A'
: // MDX error: print extra attributes + stacktrace
`${errorJSON}\n${error.stack}`;

return callback(
new Error(
`MDX compilation failed for file ${logger.path(filePath)}\nCause: ${
error.message
}\nDetails:\n${JSON.stringify(error, null, 2)}`,
}\nDetails:\n${errorDetails}`,
// TODO error cause doesn't seem to be used by Webpack stats.errors :s
{cause: error},
),
Expand Down
Loading