Improve subError rendering
This commit is contained in:
parent
be5fd46005
commit
eba89ed9c5
|
@ -4,6 +4,7 @@ const indentString = require("indent-string");
|
||||||
const supportsColor = require("supports-color");
|
const supportsColor = require("supports-color");
|
||||||
const matchVirtualProperty = require("@validatem/match-virtual-property");
|
const matchVirtualProperty = require("@validatem/match-virtual-property");
|
||||||
const asExpression = require("as-expression");
|
const asExpression = require("as-expression");
|
||||||
|
const syncpipe = require("syncpipe");
|
||||||
|
|
||||||
const AggregrateValidationError = require("./aggregrate-validation-error");
|
const AggregrateValidationError = require("./aggregrate-validation-error");
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ function renderErrorList(errors, subErrorLevels = 0) {
|
||||||
? `${lineCharacter} ${joinPathSegments(pathSegments)}: ${error.message}`
|
? `${lineCharacter} ${joinPathSegments(pathSegments)}: ${error.message}`
|
||||||
: `${lineCharacter} ${error.message}`;
|
: `${lineCharacter} ${error.message}`;
|
||||||
|
|
||||||
return indentString(message, subErrorLevels * 4);
|
return message;
|
||||||
} else {
|
} else {
|
||||||
return (pathSegments.length > 0)
|
return (pathSegments.length > 0)
|
||||||
? ` - At ${joinPathSegments(pathSegments)}: ${error.message}`
|
? ` - At ${joinPathSegments(pathSegments)}: ${error.message}`
|
||||||
|
@ -64,8 +65,17 @@ function renderErrorList(errors, subErrorLevels = 0) {
|
||||||
|
|
||||||
if (error.subErrors != null && error.subErrors.length > 0) {
|
if (error.subErrors != null && error.subErrors.length > 0) {
|
||||||
let renderedSubErrors = renderErrorList(error.subErrors, subErrorLevels + 1);
|
let renderedSubErrors = renderErrorList(error.subErrors, subErrorLevels + 1);
|
||||||
|
let isLastError = (i === errors.length - 1);
|
||||||
|
|
||||||
return mainLine + "\n" + renderedSubErrors;
|
if (subErrorLevels > 0 && !isLastError) {
|
||||||
|
return syncpipe(renderedSubErrors, [
|
||||||
|
(_) => indentString(_, 3),
|
||||||
|
(_) => indentString(_, 1, { indent: "│" }),
|
||||||
|
(_) => mainLine + "\n" + _
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
return mainLine + "\n" + indentString(renderedSubErrors, 4);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return mainLine;
|
return mainLine;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1148,6 +1148,13 @@ supports-color@^7.1.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
has-flag "^4.0.0"
|
has-flag "^4.0.0"
|
||||||
|
|
||||||
|
syncpipe@^1.0.0:
|
||||||
|
version "1.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/syncpipe/-/syncpipe-1.0.0.tgz#170340f813150bc8fcb8878b1b9c71ea0ccd3727"
|
||||||
|
integrity sha512-cdiAFTnFJRvUaNPDc2n9CqoFvtIL3+JUMJZrC3kA3FzpugHOqu0TvkgNwmnxPZ5/WjAzMcfMS3xm+AO7rg/j/w==
|
||||||
|
dependencies:
|
||||||
|
assure-array "^1.0.0"
|
||||||
|
|
||||||
table@^5.2.3:
|
table@^5.2.3:
|
||||||
version "5.4.6"
|
version "5.4.6"
|
||||||
resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e"
|
resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e"
|
||||||
|
|
Loading…
Reference in a new issue