Improve multi-level subError rendering (eg. nested 'either')
This commit is contained in:
parent
529df8413a
commit
558b9ead9c
|
@ -30,7 +30,7 @@ if (supportsColor.stderr) {
|
||||||
closeColor = "";
|
closeColor = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderErrorList(errors, isSubErrors = false) {
|
function renderErrorList(errors, subErrorLevels = 0) {
|
||||||
let rephrasedErrors = errors.map((error, i) => {
|
let rephrasedErrors = errors.map((error, i) => {
|
||||||
let pathSegments = error.path.map((segment) => {
|
let pathSegments = error.path.map((segment) => {
|
||||||
if (segment == null) {
|
if (segment == null) {
|
||||||
|
@ -49,25 +49,23 @@ function renderErrorList(errors, isSubErrors = false) {
|
||||||
: "└─";
|
: "└─";
|
||||||
|
|
||||||
let mainLine = asExpression(() => {
|
let mainLine = asExpression(() => {
|
||||||
if (pathSegments.length > 0) {
|
if (subErrorLevels > 0) {
|
||||||
if (isSubErrors) {
|
let message = (pathSegments.length > 0)
|
||||||
return ` ${lineCharacter} ${joinPathSegments(pathSegments)}: ${error.message}`;
|
? `${lineCharacter} ${joinPathSegments(pathSegments)}: ${error.message}`
|
||||||
|
: `${lineCharacter} ${error.message}`;
|
||||||
|
|
||||||
|
return indentString(message, subErrorLevels * 4);
|
||||||
} else {
|
} else {
|
||||||
return ` - At ${joinPathSegments(pathSegments)}: ${error.message}`;
|
return (pathSegments.length > 0)
|
||||||
}
|
? ` - At ${joinPathSegments(pathSegments)}: ${error.message}`
|
||||||
} else {
|
: ` - ${error.message}`;
|
||||||
if (isSubErrors) {
|
|
||||||
return ` ${lineCharacter} ${error.message}`;
|
|
||||||
} else {
|
|
||||||
return ` - ${error.message}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error.subErrors != null && error.subErrors.length > 0) {
|
if (error.subErrors != null && error.subErrors.length > 0) {
|
||||||
let renderedSubErrors = renderErrorList(error.subErrors, true);
|
let renderedSubErrors = renderErrorList(error.subErrors, subErrorLevels + 1);
|
||||||
|
|
||||||
return mainLine + "\n" + indentString(renderedSubErrors, 2);
|
return mainLine + "\n" + renderedSubErrors;
|
||||||
} else {
|
} else {
|
||||||
return mainLine;
|
return mainLine;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue