mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-17 02:56:57 +02:00
fix(v2): fix empty link error message (#3435)
* fix empty link error message * fix snapshot
This commit is contained in:
parent
37989a00c3
commit
7ffe93903c
2 changed files with 8 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`transformAsset plugin fail if asset url is absent 1`] = `"Markdown link url is mandatory. filePath=packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/fixtures/noUrl.md, title=null"`;
|
exports[`transformAsset plugin fail if asset url is absent 1`] = `"Markdown link url is mandatory. filePath=packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/fixtures/noUrl.md, title=asset, line=1"`;
|
||||||
|
|
||||||
exports[`transformAsset plugin pathname protocol 1`] = `
|
exports[`transformAsset plugin pathname protocol 1`] = `
|
||||||
"[asset](pathname:///asset/unchecked.pdf)
|
"[asset](pathname:///asset/unchecked.pdf)
|
||||||
|
|
|
@ -119,10 +119,16 @@ async function convertToAssetLinkIfNeeded({
|
||||||
|
|
||||||
async function processLinkNode({node, index, parent, filePath, staticDir}) {
|
async function processLinkNode({node, index, parent, filePath, staticDir}) {
|
||||||
if (!node.url) {
|
if (!node.url) {
|
||||||
|
// try to improve error feedback
|
||||||
|
// see https://github.com/facebook/docusaurus/issues/3309#issuecomment-690371675
|
||||||
|
const title =
|
||||||
|
node.title || (node.children[0] && node.children[0].value) || '?';
|
||||||
|
const line =
|
||||||
|
(node.position && node.position.start && node.position.start.line) || '?';
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Markdown link url is mandatory. filePath=${toRelativePath(
|
`Markdown link url is mandatory. filePath=${toRelativePath(
|
||||||
filePath,
|
filePath,
|
||||||
)}, title=${node.title}`,
|
)}, title=${title}, line=${line}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue