mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-28 00:17:14 +02:00
refactor(v2): blog/docs: add more context in error messages (#4989)
* refactor(v2): blog/docs: add more context in error messages * more error handling
This commit is contained in:
parent
b54ec72389
commit
1b0acc5547
3 changed files with 178 additions and 116 deletions
|
@ -32,6 +32,7 @@ import globby from 'globby';
|
|||
import {getDocsDirPaths} from './versions';
|
||||
import {stripPathNumberPrefixes} from './numberPrefix';
|
||||
import {validateDocFrontMatter} from './docFrontMatter';
|
||||
import chalk from 'chalk';
|
||||
|
||||
type LastUpdateOptions = Pick<
|
||||
PluginOptions,
|
||||
|
@ -102,7 +103,7 @@ export async function readVersionDocs(
|
|||
);
|
||||
}
|
||||
|
||||
export function processDocMetadata({
|
||||
function doProcessDocMetadata({
|
||||
docFile,
|
||||
versionMetadata,
|
||||
context,
|
||||
|
@ -262,3 +263,21 @@ export function processDocMetadata({
|
|||
frontMatter,
|
||||
};
|
||||
}
|
||||
|
||||
export function processDocMetadata(args: {
|
||||
docFile: DocFile;
|
||||
versionMetadata: VersionMetadata;
|
||||
context: LoadContext;
|
||||
options: MetadataOptions;
|
||||
}): DocMetadataBase {
|
||||
try {
|
||||
return doProcessDocMetadata(args);
|
||||
} catch (e) {
|
||||
console.error(
|
||||
chalk.red(
|
||||
`Can't process doc metadatas for doc at path "${args.docFile.filePath}" in version "${args.versionMetadata.versionName}"`,
|
||||
),
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ import {
|
|||
getLoadedContentTranslationFiles,
|
||||
} from './translations';
|
||||
import {CategoryMetadataFilenamePattern} from './sidebarItemsGenerator';
|
||||
import chalk from 'chalk';
|
||||
|
||||
export default function pluginContentDocs(
|
||||
context: LoadContext,
|
||||
|
@ -163,7 +164,7 @@ export default function pluginContentDocs(
|
|||
return Promise.all(docFiles.map(processVersionDoc));
|
||||
}
|
||||
|
||||
async function loadVersion(
|
||||
async function doLoadVersion(
|
||||
versionMetadata: VersionMetadata,
|
||||
): Promise<LoadedVersion> {
|
||||
const unprocessedSidebars = loadSidebars(
|
||||
|
@ -267,6 +268,19 @@ export default function pluginContentDocs(
|
|||
};
|
||||
}
|
||||
|
||||
async function loadVersion(versionMetadata: VersionMetadata) {
|
||||
try {
|
||||
return await doLoadVersion(versionMetadata);
|
||||
} catch (e) {
|
||||
console.error(
|
||||
chalk.red(
|
||||
`Loading of version failed for version "${versionMetadata.versionName}"`,
|
||||
),
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
loadedVersions: await Promise.all(versionsMetadata.map(loadVersion)),
|
||||
};
|
||||
|
@ -307,7 +321,7 @@ export default function pluginContentDocs(
|
|||
return routes.sort((a, b) => a.path.localeCompare(b.path));
|
||||
};
|
||||
|
||||
async function handleVersion(loadedVersion: LoadedVersion) {
|
||||
async function doCreateVersionRoutes(loadedVersion: LoadedVersion) {
|
||||
const versionMetadataPropPath = await createData(
|
||||
`${docuHash(
|
||||
`version-${loadedVersion.versionName}-metadata-prop`,
|
||||
|
@ -334,7 +348,20 @@ export default function pluginContentDocs(
|
|||
});
|
||||
}
|
||||
|
||||
await Promise.all(loadedVersions.map(handleVersion));
|
||||
async function createVersionRoutes(loadedVersion: LoadedVersion) {
|
||||
try {
|
||||
return await doCreateVersionRoutes(loadedVersion);
|
||||
} catch (e) {
|
||||
console.error(
|
||||
chalk.red(
|
||||
`Can't create version routes for version "${loadedVersion.versionName}"`,
|
||||
),
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(loadedVersions.map(createVersionRoutes));
|
||||
|
||||
setGlobalData<GlobalPluginData>({
|
||||
path: normalizeUrl([baseUrl, options.routeBasePath]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue