mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-24 20:17:50 +02:00
refactor: remove "error" reporting level, move reportMessage to logger (#7642)
This commit is contained in:
parent
1b9bec1042
commit
bfba6a8b02
16 changed files with 117 additions and 116 deletions
|
@ -5,9 +5,6 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import logger from '@docusaurus/logger';
|
||||
import type {ReportingSeverity} from '@docusaurus/types';
|
||||
|
||||
/** Removes a given string suffix from `str`. */
|
||||
export function removeSuffix(str: string, suffix: string): string {
|
||||
if (suffix === '') {
|
||||
|
@ -60,43 +57,3 @@ export async function findAsyncSequential<T>(
|
|||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a message and reports it according to the severity that the user wants.
|
||||
*
|
||||
* - `ignore`: completely no-op
|
||||
* - `log`: uses the `INFO` log level
|
||||
* - `warn`: uses the `WARN` log level
|
||||
* - `error`: uses the `ERROR` log level
|
||||
* - `throw`: aborts the process, throws the error.
|
||||
*
|
||||
* Since the logger doesn't have logging level filters yet, these severities
|
||||
* mostly just differ by their colors.
|
||||
*
|
||||
* @throws In addition to throwing when `reportingSeverity === "throw"`, this
|
||||
* function also throws if `reportingSeverity` is not one of the above.
|
||||
*/
|
||||
export function reportMessage(
|
||||
message: string,
|
||||
reportingSeverity: ReportingSeverity,
|
||||
): void {
|
||||
switch (reportingSeverity) {
|
||||
case 'ignore':
|
||||
break;
|
||||
case 'log':
|
||||
logger.info(message);
|
||||
break;
|
||||
case 'warn':
|
||||
logger.warn(message);
|
||||
break;
|
||||
case 'error':
|
||||
logger.error(message);
|
||||
break;
|
||||
case 'throw':
|
||||
throw new Error(message);
|
||||
default:
|
||||
throw new Error(
|
||||
`Unexpected "reportingSeverity" value: ${reportingSeverity}.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue