From 250395a96a5b3ee6f2efe5d0936398fa4346e525 Mon Sep 17 00:00:00 2001 From: Joel Marcey Date: Wed, 20 Dec 2017 19:47:13 -0800 Subject: [PATCH] Better error when parsing headerLinks.doc fields (#337) Closes #309 --- lib/core/nav/HeaderNav.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/core/nav/HeaderNav.js b/lib/core/nav/HeaderNav.js index f2763276b3..10db9f9d33 100644 --- a/lib/core/nav/HeaderNav.js +++ b/lib/core/nav/HeaderNav.js @@ -133,17 +133,25 @@ class HeaderNav extends React.Component { : ''; const id = langPart + versionPart + link.doc; if (!Metadata[id]) { - if (id != link.doc) { - throw new Error( - "It looks like you've enabled language support, but haven't provided translated files. The document with id: '" + - id + - "' doesn't exist." - ); + let errorStr = + "Processing the following `doc` field in `headerLinks` within `siteConfig.js`: '" + + link.doc + + "'"; + if (id === link.doc) { + errorStr += + ' It looks like there is no document with that id that exists in your docs directory. Please double check the spelling of your `doc` field and the `id` fields of your docs.'; + } else { + errorStr += + '. Check the spelling of your `doc` field. If that seems sane, and a document in your docs folder exists with that `id` value, \nthen this is likely a bug in Docusaurus.' + + ' Docusaurus thinks one or both of translations (currently set to: ' + + env.translation.enabled + + ') or versioning (currently set to: ' + + env.versioning.enabled + + ") is enabled when maybe they should not be. \nThus my internal id for this doc is: '" + + id + + "'. Please file an issue for this possible bug on GitHub."; } - throw new Error( - 'A headerLink is specified with a document that does not exist. No document exists with id: ' + - link.doc - ); + throw new Error(errorStr); } href = this.props.config.baseUrl + Metadata[id].permalink; } else if (link.page) {