refactor: remove "error" reporting level, move reportMessage to logger (#7642)

This commit is contained in:
Joshua Chen 2022-06-17 20:51:00 +08:00 committed by GitHub
parent 1b9bec1042
commit bfba6a8b02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 117 additions and 116 deletions

View file

@ -161,3 +161,8 @@ exports[`normalizeConfig throws error for unknown field 1`] = `
If you still want these fields to be in your configuration, put them in the "customFields" field.
See https://docusaurus.io/docs/api/docusaurus-config/#customfields"
`;
exports[`normalizeConfig throws for "error" reporting severity 1`] = `
""onBrokenLinks" must be one of [ignore, log, warn, throw]
"
`;

View file

@ -308,6 +308,20 @@ describe('normalizeConfig', () => {
),
).toThrowErrorMatchingSnapshot();
});
it('throws for "error" reporting severity', () => {
expect(() =>
validateConfig(
{
title: 'Site',
url: 'https://example.com',
baseUrl: '/',
onBrokenLinks: 'error',
},
'docusaurus.config.js',
),
).toThrowErrorMatchingSnapshot();
});
});
describe('config warnings', () => {

View file

@ -11,12 +11,7 @@ import _ from 'lodash';
import logger from '@docusaurus/logger';
import combinePromises from 'combine-promises';
import {matchRoutes} from 'react-router-config';
import {
removePrefix,
removeSuffix,
reportMessage,
resolvePathname,
} from '@docusaurus/utils';
import {removePrefix, removeSuffix, resolvePathname} from '@docusaurus/utils';
import {getAllFinalRoutes} from './utils';
import type {RouteConfig, ReportingSeverity} from '@docusaurus/types';
@ -247,6 +242,6 @@ export async function handleBrokenLinks({
const errorMessage = getBrokenLinksErrorMessage(allBrokenLinks);
if (errorMessage) {
reportMessage(errorMessage, onBrokenLinks);
logger.report(onBrokenLinks)(errorMessage);
}
}

View file

@ -174,13 +174,13 @@ export const ConfigSchema = Joi.object<DocusaurusConfig>({
trailingSlash: Joi.boolean(), // No default value! undefined = retrocompatible legacy behavior!
i18n: I18N_CONFIG_SCHEMA,
onBrokenLinks: Joi.string()
.equal('ignore', 'log', 'warn', 'error', 'throw')
.equal('ignore', 'log', 'warn', 'throw')
.default(DEFAULT_CONFIG.onBrokenLinks),
onBrokenMarkdownLinks: Joi.string()
.equal('ignore', 'log', 'warn', 'error', 'throw')
.equal('ignore', 'log', 'warn', 'throw')
.default(DEFAULT_CONFIG.onBrokenMarkdownLinks),
onDuplicateRoutes: Joi.string()
.equal('ignore', 'log', 'warn', 'error', 'throw')
.equal('ignore', 'log', 'warn', 'throw')
.default(DEFAULT_CONFIG.onDuplicateRoutes),
organizationName: Joi.string().allow(''),
staticDirectories: Joi.array()

View file

@ -7,12 +7,12 @@
import query from 'querystring';
import _ from 'lodash';
import logger from '@docusaurus/logger';
import {
docuHash,
normalizeUrl,
simpleHash,
escapePath,
reportMessage,
} from '@docusaurus/utils';
import {getAllFinalRoutes} from './utils';
import type {
@ -228,15 +228,13 @@ export function handleDuplicateRoutes(
return false;
});
if (duplicatePaths.length > 0) {
const finalMessage = `Duplicate routes found!
${duplicatePaths
.map(
(duplicateRoute) =>
`- Attempting to create page at ${duplicateRoute}, but a page already exists at this route.`,
)
.join('\n')}
logger.report(
onDuplicateRoutes,
)`Duplicate routes found!${duplicatePaths.map(
(duplicateRoute) =>
logger.interpolate`Attempting to create page at url=${duplicateRoute}, but a page already exists at this route.`,
)}
This could lead to non-deterministic routing behavior.`;
reportMessage(finalMessage, onDuplicateRoutes);
}
}