Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(v2): include path in error about non-existent ids #4969

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`sidebar site with wrong sidebar content 1`] = `
"Bad sidebars file.
"Bad sidebar file at 'packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/wrong-sidebars.json'.
These sidebar document ids do not exist:
- goku,

Expand Down
5 changes: 4 additions & 1 deletion packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ export default function pluginContentDocs(
const sidebarsUtils = createSidebarsUtils(sidebars);

const validDocIds = Object.keys(docsBaseById);
sidebarsUtils.checkSidebarsDocIds(validDocIds);
sidebarsUtils.checkSidebarsDocIds(
validDocIds,
versionMetadata.sidebarFilePath as string,
);

// Add sidebar/next/previous to the docs
function addNavData(doc: DocMetadataBase): DocMetadata {
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-plugin-content-docs/src/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
PluginOptions,
} from './types';
import {mapValues, flatten, flatMap, difference, pick, memoize} from 'lodash';
import {getElementsAround} from '@docusaurus/utils';
import {getElementsAround, toMessageRelativeFilePath} from '@docusaurus/utils';
import combinePromises from 'combine-promises';
import {DefaultSidebarItemsGenerator} from './sidebarItemsGenerator';
import path from 'path';
Expand Down Expand Up @@ -480,12 +480,12 @@ export function createSidebarsUtils(sidebars: Sidebars) {
}
}

function checkSidebarsDocIds(validDocIds: string[]) {
function checkSidebarsDocIds(validDocIds: string[], sidebarFilePath: string) {
const allSidebarDocIds = flatten(Object.values(sidebarNameToDocIds));
const invalidSidebarDocIds = difference(allSidebarDocIds, validDocIds);
if (invalidSidebarDocIds.length > 0) {
throw new Error(
`Bad sidebars file.
`Bad sidebar file at '${toMessageRelativeFilePath(sidebarFilePath)}'.
These sidebar document ids do not exist:
- ${invalidSidebarDocIds.sort().join('\n- ')},

Expand Down