mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-28 14:08:21 +02:00
refactor(v2): cleanup console output (#4979)
* refactor(v2): cleanup console output * fix jest issue Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
8501db78a1
commit
41d9288e3d
86 changed files with 382 additions and 339 deletions
|
@ -118,18 +118,18 @@ function assertIsCategory(
|
|||
assertItem(item, ['items', 'label', 'collapsed', 'customProps']);
|
||||
if (typeof item.label !== 'string') {
|
||||
throw new Error(
|
||||
`Error loading ${JSON.stringify(item)}. "label" must be a string.`,
|
||||
`Error loading ${JSON.stringify(item)}: "label" must be a string.`,
|
||||
);
|
||||
}
|
||||
if (!Array.isArray(item.items)) {
|
||||
throw new Error(
|
||||
`Error loading ${JSON.stringify(item)}. "items" must be an array.`,
|
||||
`Error loading ${JSON.stringify(item)}: "items" must be an array.`,
|
||||
);
|
||||
}
|
||||
// "collapsed" is an optional property
|
||||
if (item.hasOwnProperty('collapsed') && typeof item.collapsed !== 'boolean') {
|
||||
throw new Error(
|
||||
`Error loading ${JSON.stringify(item)}. "collapsed" must be a boolean.`,
|
||||
`Error loading ${JSON.stringify(item)}: "collapsed" must be a boolean.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -140,14 +140,14 @@ function assertIsAutogenerated(
|
|||
assertItem(item, ['dirName', 'customProps']);
|
||||
if (typeof item.dirName !== 'string') {
|
||||
throw new Error(
|
||||
`Error loading ${JSON.stringify(item)}. "dirName" must be a string.`,
|
||||
`Error loading ${JSON.stringify(item)}: "dirName" must be a string.`,
|
||||
);
|
||||
}
|
||||
if (item.dirName.startsWith('/') || item.dirName.endsWith('/')) {
|
||||
throw new Error(
|
||||
`Error loading ${JSON.stringify(
|
||||
item,
|
||||
)}. "dirName" must be a dir path relative to the docs folder root, and should not start or end with /`,
|
||||
)}: "dirName" must be a dir path relative to the docs folder root, and should not start or end with slash`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -158,13 +158,13 @@ function assertIsDoc(
|
|||
assertItem(item, ['id', 'label', 'customProps']);
|
||||
if (typeof item.id !== 'string') {
|
||||
throw new Error(
|
||||
`Error loading ${JSON.stringify(item)}. "id" must be a string.`,
|
||||
`Error loading ${JSON.stringify(item)}: "id" must be a string.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (item.label && typeof item.label !== 'string') {
|
||||
throw new Error(
|
||||
`Error loading ${JSON.stringify(item)}. "label" must be a string.`,
|
||||
`Error loading ${JSON.stringify(item)}: "label" must be a string.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -175,12 +175,12 @@ function assertIsLink(
|
|||
assertItem(item, ['href', 'label', 'customProps']);
|
||||
if (typeof item.href !== 'string') {
|
||||
throw new Error(
|
||||
`Error loading ${JSON.stringify(item)}. "href" must be a string.`,
|
||||
`Error loading ${JSON.stringify(item)}: "href" must be a string.`,
|
||||
);
|
||||
}
|
||||
if (typeof item.label !== 'string') {
|
||||
throw new Error(
|
||||
`Error loading ${JSON.stringify(item)}. "label" must be a string.`,
|
||||
`Error loading ${JSON.stringify(item)}: "label" must be a string.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -224,12 +224,12 @@ function normalizeItem(item: SidebarItemJSON): UnprocessedSidebarItem[] {
|
|||
default: {
|
||||
const extraMigrationError =
|
||||
item.type === 'subcategory'
|
||||
? "Docusaurus v2: 'subcategory' has been renamed as 'category'"
|
||||
? 'Docusaurus v2: "subcategory" has been renamed as "category".'
|
||||
: '';
|
||||
throw new Error(
|
||||
`Unknown sidebar item type [${
|
||||
`Unknown sidebar item type "${
|
||||
item.type
|
||||
}]. Sidebar item=${JSON.stringify(item)} ${extraMigrationError}`,
|
||||
}". Sidebar item is ${JSON.stringify(item)}.\n${extraMigrationError}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -485,11 +485,13 @@ export function createSidebarsUtils(sidebars: Sidebars) {
|
|||
const invalidSidebarDocIds = difference(allSidebarDocIds, validDocIds);
|
||||
if (invalidSidebarDocIds.length > 0) {
|
||||
throw new Error(
|
||||
`Bad sidebar file at '${toMessageRelativeFilePath(sidebarFilePath)}'.
|
||||
`Invalid sidebar file at "${toMessageRelativeFilePath(
|
||||
sidebarFilePath,
|
||||
)}".
|
||||
These sidebar document ids do not exist:
|
||||
- ${invalidSidebarDocIds.sort().join('\n- ')},
|
||||
- ${invalidSidebarDocIds.sort().join('\n- ')}
|
||||
|
||||
Available document ids=
|
||||
Available document ids are:
|
||||
- ${validDocIds.sort().join('\n- ')}`,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue