Move DebugError into cli/ (#14464)

This commit is contained in:
fisker Cheung authored and GitHub committed 2023-03-08 09:08:59 +08:00
1 parent 57b37a3c27
commit 8865ade202
2 files changed
+6 -5

No files matched your search

+5 -3
View File
@@ -18,6 +18,8 @@ function diff(a, b) {
return createTwoFilesPatch("", "", a, b, "", "", { context: 2 });
}
class DebugError extends Error {}
function handleError(context, filename, error, printedFilename) {
if (error instanceof errors.UndefinedParserError) {
// Can't test on CI, `isTTY()` is always false, see ./is-tty.js
@@ -52,7 +54,7 @@ function handleError(context, filename, error, printedFilename) {
context.logger.error(error.message);
// If validation fails for one file, it will fail for all of them.
process.exit(1);
} else if (error instanceof errors.DebugError) {
} else if (error instanceof DebugError) {
// `invalid.js: Some debug error message`
context.logger.error(`${filename}: ${error.message}`);
} else {
@@ -132,7 +134,7 @@ async function format(context, input, opt) {
const pp = await prettier.format(input, opt);
const pppp = await prettier.format(pp, opt);
if (pp !== pppp) {
throw new errors.DebugError(
throw new DebugError(
"prettier(input) !== prettier(prettier(input))\n" + diff(pp, pppp)
);
} else {
@@ -151,7 +153,7 @@ async function format(context, input, opt) {
ast.length > MAX_AST_SIZE || past.length > MAX_AST_SIZE
? "AST diff too large to render"
: diff(ast, past);
throw new errors.DebugError(
throw new DebugError(
"ast(input) !== ast(prettier(input))\n" +
astDiff +
"\n" +
+1 -2
View File
@@ -1,6 +1,5 @@
class ConfigError extends Error {}
class DebugError extends Error {}
class UndefinedParserError extends Error {}
class ArgExpansionBailout extends Error {}
export { ConfigError, DebugError, UndefinedParserError, ArgExpansionBailout };
export { ConfigError, UndefinedParserError, ArgExpansionBailout };