Merge pull request #61 from facebookexperimental/error-messages

Add better error messages for most common cases
This commit is contained in:
Frank Li 2017-08-10 13:46:58 -07:00 committed by GitHub
commit db7a7394b3
9 changed files with 60 additions and 12 deletions

View file

@ -56,7 +56,9 @@ function readCategories(sidebar) {
if (metadata.next) {
if (!articles[metadata.next]) {
throw new Error(
"`next: " + metadata.next + "` in " + metadata.id + " doesn't exist"
metadata.version
? `Improper sidebars file for version ${metadata.version}. Make sure that all documents with ids specified in this version's sidebar file exist and that no ids are repeated.`
: `Improper sidebars.json file. Make sure that documents with the ids specified in sidebars.json exist and that no ids are repeated.`
);
}
previous[articles[metadata.next].id] = metadata.id;

View file

@ -32,7 +32,12 @@ if (fs.existsSync(CWD + "/languages.js")) {
}
function readSidebar() {
let allSidebars = require(CWD + "/sidebars.json");
let allSidebars;
if (fs.existsSync(CWD + "/sidebars.json")) {
allSidebars = require(CWD + "/sidebars.json");
} else {
allSidebars = {};
}
Object.assign(allSidebars, versionFallback.sidebarData());
const order = {};
@ -155,7 +160,7 @@ function processMetadata(file) {
metadata.previous = language + "-" + order[id].previous;
}
}
return { metadata, rawContent: rawContent };
}

View file

@ -157,6 +157,10 @@ function execute(port) {
});
const metadata = Metadata[links[url]];
if (!metadata) {
next();
return;
}
const language = metadata.language;
let file;
@ -438,7 +442,6 @@ function execute(port) {
res.send(cssContent);
});
/* serve static content first from user folder then from docusaurus */
app.use(
siteConfig.baseUrl + "docs/assets/",
express.static(CWD + "/../docs/assets")

View file

@ -20,7 +20,7 @@ const ENABLE_TRANSLATION = fs.existsSync(CWD + "/languages.js");
let versions;
if (fs.existsSync(CWD + "/versions.json")) {
versions = require(CWD + "/versions.json");
versions = require(CWD + "/versions.json");
} else {
versions = [];
}
@ -124,7 +124,9 @@ function docVersion(id, req_version) {
return versions[i];
}
}
return null;
throw new Error(
`No document available to use for version ${req_version} of document with id ${id}. Verify that all version files are correct.`
);
}
// returns whether a given file has content that differ from the
@ -226,7 +228,7 @@ function docData() {
// return the version of the sidebar to use given a requested version
function sidebarVersion(req_version) {
// iterate through versions until a version less than or equal to the requested
// is found, then check if that verison has an available file to use
// is found, then check if that version has an available file to use
let requestedFound = false;
for (let i = 0; i < versions.length; i++) {
if (versions[i] === req_version) {
@ -243,7 +245,9 @@ function sidebarVersion(req_version) {
return versions[i];
}
}
return null;
throw new Error(
`No sidebar file available to use for version ${req_version}. Verify that all version files are correct.`
);
}
// return whether or not the current sidebars.json file differs from the