Initial changes to error messages

This commit is contained in:
Frank Li 2017-08-09 15:43:30 -07:00
parent e285f93c1b
commit b256d2f8d9
7 changed files with 45 additions and 6 deletions

View file

@ -16,5 +16,17 @@ require("babel-register")({
presets: ["react", "latest"]
});
// initial check that required files are present
const chalk = require("chalk");
const fs = require("fs");
const CWD = process.cwd();
if (!fs.existsSync(CWD + "/siteConfig.js")) {
console.error(
chalk.red("Error: No siteConfig.js file found in website folder!")
);
process.exit(1);
}
const generate = require("./server/generate.js");
generate();

View file

@ -128,6 +128,12 @@ class HeaderNav extends React.Component {
"-" +
link.doc;
}
if (!Metadata[id]) {
throw new Error(
"A headerLink is specified with a document that does not exist. No document exists with id: " +
link.doc
);
}
href = this.props.config.baseUrl + Metadata[id].permalink;
} else if (link.page) {
if (fs.existsSync(CWD + "/pages/en/" + link.page + ".js")) {

View file

@ -56,7 +56,7 @@ function readCategories(sidebar) {
if (metadata.next) {
if (!articles[metadata.next]) {
throw new Error(
"`next: " + metadata.next + "` in " + metadata.id + " doesn't exist"
"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 = {};

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

@ -16,6 +16,18 @@ require("babel-register")({
presets: ["react", "latest"]
});
// initial check that required files are present
const chalk = require("chalk");
const fs = require("fs");
const CWD = process.cwd();
if (!fs.existsSync(CWD + "/siteConfig.js")) {
console.error(
chalk.red("Error: No siteConfig.js file found in website folder!")
);
process.exit(1);
}
const program = require("commander");
program.option("--port <number>", "Specify port number").parse(process.argv);

View file

@ -11,6 +11,7 @@
"babel-register": "^6.24.1",
"babel-traverse": "^6.25.0",
"babylon": "^6.17.4",
"chalk": "^2.1.0",
"classnames": "^2.2.5",
"commander": "^2.11.0",
"diff": "^3.3.0",