@naturalcycles/nodejs-lib 15.122.0 → 15.122.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1202,22 +1202,28 @@ function executeValidation(fn, builtSchema, input, opt = {}, defaultInputName) {
|
|
|
1202
1202
|
// rewritten into below (a property name may itself contain a dot).
|
|
1203
1203
|
// Root errors (empty instancePath) resolve to undefined - there the value is the whole Input,
|
|
1204
1204
|
// which is printed anyway.
|
|
1205
|
+
// `required` errors also resolve to undefined - their instancePath points at the parent object
|
|
1206
|
+
// that lacks the property, so `got:` would print that whole object - noise next to the Input print.
|
|
1205
1207
|
const failingValueByError = new Map(errors.map(e => [
|
|
1206
1208
|
e,
|
|
1207
|
-
e.instancePath
|
|
1209
|
+
e.instancePath && e.keyword !== 'required'
|
|
1210
|
+
? getValueAtJsonPointer(inputForPrint, e.instancePath)
|
|
1211
|
+
: undefined,
|
|
1208
1212
|
]));
|
|
1209
1213
|
applyImprovementsOnErrorMessages(errors, builtSchema);
|
|
1210
1214
|
// Same line format as Ajv's errorsText().
|
|
1211
|
-
// Each
|
|
1215
|
+
// Each error line is followed by a `Got: ...` line printing the narrow failing value itself,
|
|
1212
1216
|
// so it stays visible even when the Input print below gets truncated for large inputs.
|
|
1217
|
+
// `Got` is a separate line (and is allowed to print multi-line) on purpose: consumers that
|
|
1218
|
+
// only take the first line of the message keep getting the unchanged (pre-Got) error line.
|
|
1213
1219
|
let message = errors
|
|
1214
|
-
.
|
|
1215
|
-
|
|
1220
|
+
.flatMap(e => {
|
|
1221
|
+
const lines = [`${dataVar}${e.instancePath} ${e.message}`];
|
|
1216
1222
|
const value = failingValueByError.get(e);
|
|
1217
1223
|
if (value !== undefined) {
|
|
1218
|
-
|
|
1224
|
+
lines.push(`Got: ${_inspect(value, { maxLen: 500 })}`);
|
|
1219
1225
|
}
|
|
1220
|
-
return
|
|
1226
|
+
return lines;
|
|
1221
1227
|
})
|
|
1222
1228
|
.join(separator);
|
|
1223
1229
|
const inputStringified = _inspect(inputForPrint, { maxLen: 4000 });
|
package/package.json
CHANGED
|
@@ -1732,26 +1732,32 @@ function executeValidation<OUT>(
|
|
|
1732
1732
|
// rewritten into below (a property name may itself contain a dot).
|
|
1733
1733
|
// Root errors (empty instancePath) resolve to undefined - there the value is the whole Input,
|
|
1734
1734
|
// which is printed anyway.
|
|
1735
|
+
// `required` errors also resolve to undefined - their instancePath points at the parent object
|
|
1736
|
+
// that lacks the property, so `got:` would print that whole object - noise next to the Input print.
|
|
1735
1737
|
const failingValueByError = new Map<ErrorObject, unknown>(
|
|
1736
1738
|
errors.map(e => [
|
|
1737
1739
|
e,
|
|
1738
|
-
e.instancePath
|
|
1740
|
+
e.instancePath && e.keyword !== 'required'
|
|
1741
|
+
? getValueAtJsonPointer(inputForPrint, e.instancePath)
|
|
1742
|
+
: undefined,
|
|
1739
1743
|
]),
|
|
1740
1744
|
)
|
|
1741
1745
|
|
|
1742
1746
|
applyImprovementsOnErrorMessages(errors, builtSchema)
|
|
1743
1747
|
|
|
1744
1748
|
// Same line format as Ajv's errorsText().
|
|
1745
|
-
// Each
|
|
1749
|
+
// Each error line is followed by a `Got: ...` line printing the narrow failing value itself,
|
|
1746
1750
|
// so it stays visible even when the Input print below gets truncated for large inputs.
|
|
1751
|
+
// `Got` is a separate line (and is allowed to print multi-line) on purpose: consumers that
|
|
1752
|
+
// only take the first line of the message keep getting the unchanged (pre-Got) error line.
|
|
1747
1753
|
let message = errors
|
|
1748
|
-
.
|
|
1749
|
-
|
|
1754
|
+
.flatMap(e => {
|
|
1755
|
+
const lines = [`${dataVar}${e.instancePath} ${e.message}`]
|
|
1750
1756
|
const value = failingValueByError.get(e)
|
|
1751
1757
|
if (value !== undefined) {
|
|
1752
|
-
|
|
1758
|
+
lines.push(`Got: ${_inspect(value, { maxLen: 500 })}`)
|
|
1753
1759
|
}
|
|
1754
|
-
return
|
|
1760
|
+
return lines
|
|
1755
1761
|
})
|
|
1756
1762
|
.join(separator)
|
|
1757
1763
|
|