mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-16 10:37:20 +02:00
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:
parent
47c955c7b0
commit
459984516b
3 changed files with 62 additions and 8 deletions
|
@ -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.`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue