mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
fix(mdx-loader): loader error message should display stacktrace if no extra MDX details (#9091)
This commit is contained in:
parent
48df4f1f0d
commit
0b3d5cb59e
1 changed files with 11 additions and 1 deletions
|
@ -162,11 +162,21 @@ export async function mdxLoader(
|
||||||
result = await processor.process({content, filePath});
|
result = await processor.process({content, filePath});
|
||||||
} catch (errorUnknown) {
|
} catch (errorUnknown) {
|
||||||
const error = errorUnknown as Error;
|
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(
|
return callback(
|
||||||
new Error(
|
new Error(
|
||||||
`MDX compilation failed for file ${logger.path(filePath)}\nCause: ${
|
`MDX compilation failed for file ${logger.path(filePath)}\nCause: ${
|
||||||
error.message
|
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
|
// TODO error cause doesn't seem to be used by Webpack stats.errors :s
|
||||||
{cause: error},
|
{cause: error},
|
||||||
),
|
),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue