Ensure some errors are logged to the console (#194)

* Clarify some error conditions in versioning

* Clarify missing doc error;

* Remove excess space

* Remove excess space part duex
This commit is contained in:
Héctor Ramos 2017-10-30 11:42:45 -07:00 committed by Joel Marcey
parent 47c955c7b0
commit 459984516b
3 changed files with 62 additions and 8 deletions

View file

@ -182,7 +182,14 @@ function processMetadata(file) {
// process metadata for all docs and save into core/metadata.js
function generateMetadataDocs() {
console.log("Generating Metadata for Docs....");
const order = readSidebar();
let order;
try {
order = readSidebar();
} catch (e) {
console.error(e);
process.exit(1);
}
const regexSubFolder = /translated_docs\/(.*)\/.*/;
@ -203,6 +210,7 @@ function generateMetadataDocs() {
if (extension === ".md" || extension === ".markdown") {
const res = processMetadata(file);
if (!res) {
return;
}

View file

@ -94,6 +94,24 @@ files.forEach(file => {
const res = extractMetadata(fs.readFileSync(file, "utf8"));
const metadata = res.metadata;
if (!metadata.original_id) {
console.error(`No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?`);
throw new Error(
`No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?`
);
}
if (!metadata.id) {
console.error(`No 'id' field found in ${file}.`);
throw new Error(
`No 'id' field found in ${file}.`
);
} else if (metadata.id.indexOf('version-') === -1) {
console.error(`The 'id' field in ${file} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`);
throw new Error(
`The 'id' field in ${file} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`
);
}
if (!(metadata.original_id in available)) {
available[metadata.original_id] = new Set();
}
@ -110,7 +128,7 @@ files.forEach(file => {
// what the requested version is
function docVersion(id, 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) {
@ -127,7 +145,7 @@ function docVersion(id, req_version) {
}
}
throw new Error(
`No document available to use for version ${req_version} of document with id ${id}. Verify that all version files are correct.`
`No document with id '${id}' available for use in version ${req_version} of the website. Verify that all version files are correct. Was the document deleted in a past version?`
);
}
@ -140,7 +158,13 @@ function diffLatestDoc(file, id) {
const latest = versions[0];
const version = docVersion(id, latest);
let version;
try {
version = docVersion(id, latest);
} catch (e) {
console.error(e);
process.exit(1);
}
if (!version) {
return true;
}
@ -211,7 +235,13 @@ function docData() {
languages.filter(language => language.enabled).forEach(language => {
versions.forEach(version => {
allIds.forEach(id => {
const useVersion = docVersion(id, version);
let useVersion;
try {
useVersion = docVersion(id, version);
} catch (e) {
console.log(e);
process.exit(1);
}
if (!useVersion) {
return;
}
@ -248,7 +278,7 @@ function sidebarVersion(req_version) {
}
}
throw new Error(
`No sidebar file available to use for version ${req_version}. Verify that all version files are correct.`
`No sidebar file available to use for version ${req_version}. Verify that 'version-${req_version}-sidebars.json' exists.`
);
}

View file

@ -52,7 +52,13 @@ function execute() {
files.forEach(file => {
const extension = path.extname(file);
if (extension === ".md" || extension === ".markdown") {
const res = readMetadata.processMetadata(file);
let res;
try {
res = readMetadata.processMetadata(file);
} catch (e) {
console.error(e);
process.exit(1);
}
if (!res) {
return;
}
@ -84,9 +90,19 @@ function execute() {
files = glob.sync(CWD + "/versioned_sidebars/*");
files.forEach(file => {
if (!file.endsWith("-sidebars.json")) {
if (file.endsWith("-sidebar.json")) {
console.warn(`Skipping ${file}. Make sure your sidebar filenames follow this format: 'version-VERSION-sidebars.json'.`);
}
return;
}
sidebarContent = JSON.parse(fs.readFileSync(file, "utf8"));
let sidebarContent;
try {
sidebarContent = JSON.parse(fs.readFileSync(file, "utf8"));
} catch (e) {
console.error(`Could not parse ${file} into json. ${e}`);
process.exit(1);
}
Object.keys(sidebarContent).forEach(sb => {
const categories = sidebarContent[sb];
Object.keys(categories).forEach(category => {