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 = "";
|
||||
}
|
||||
|
||||
function renderErrorList(errors, isSubErrors = false) {
|
||||
function renderErrorList(errors, subErrorLevels = 0) {
|
||||
let rephrasedErrors = errors.map((error, i) => {
|
||||
let pathSegments = error.path.map((segment) => {
|
||||
if (segment == null) {
|
||||
|
@ -49,25 +49,23 @@ function renderErrorList(errors, isSubErrors = false) {
|
|||
: "└─";
|
||||
|
||||
let mainLine = asExpression(() => {
|
||||
if (pathSegments.length > 0) {
|
||||
if (isSubErrors) {
|
||||
return ` ${lineCharacter} ${joinPathSegments(pathSegments)}: ${error.message}`;
|
||||
if (subErrorLevels > 0) {
|
||||
let message = (pathSegments.length > 0)
|
||||
? `${lineCharacter} ${joinPathSegments(pathSegments)}: ${error.message}`
|
||||
: `${lineCharacter} ${error.message}`;
|
||||
|
||||
return indentString(message, subErrorLevels * 4);
|
||||
} else {
|
||||
return ` - At ${joinPathSegments(pathSegments)}: ${error.message}`;
|
||||
}
|
||||
} else {
|
||||
if (isSubErrors) {
|
||||
return ` ${lineCharacter} ${error.message}`;
|
||||
} else {
|
||||
return ` - ${error.message}`;
|
||||
}
|
||||
return (pathSegments.length > 0)
|
||||
? ` - At ${joinPathSegments(pathSegments)}: ${error.message}`
|
||||
: ` - ${error.message}`;
|
||||
}
|
||||
});
|
||||
|
||||
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 {
|
||||
return mainLine;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue