Skip to content

Commit f2ef609

Browse files
committed
fix: tweaks to the new cli-array format to nest errors in an object
1 parent 753998e commit f2ef609

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/__tests__/__snapshots__/index.test.js.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ exports[`Main > given a format of \`cli\` > should output error with reconstruct
6969
7070
exports[`Main > given a format of \`cli-array\` > should output error with reconstructed codeframe [without colors] 1`] = `
7171
[
72-
"ENUM must be equal to one of the allowed values
72+
{
73+
"message": "ENUM must be equal to one of the allowed values
7374
(paragraph, codeBlock, blockquote)
7475
7576
4 | "content": [
@@ -79,12 +80,14 @@ exports[`Main > given a format of \`cli-array\` > should output error with recon
7980
7 | }
8081
8 | ]
8182
9 | }",
83+
},
8284
]
8385
`;
8486
8587
exports[`Main > given a format of \`cli-array\` > should output error with reconstructed codeframe 1`] = `
8688
[
87-
"ENUM must be equal to one of the allowed values
89+
{
90+
"message": "ENUM must be equal to one of the allowed values
8891
(paragraph, codeBlock, blockquote)
8992
9093
4 | "content": [
@@ -94,6 +97,7 @@ exports[`Main > given a format of \`cli-array\` > should output error with recon
9497
7 | }
9598
8 | ]
9699
9 | }",
100+
},
97101
]
98102
`;
99103

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export default function betterAjvErrors(schema, data, errors, options = {}) {
2121
if (format === 'cli') {
2222
return customErrors.map(customErrorToText).join('\n\n');
2323
} else if (format === 'cli-array') {
24-
return customErrors.map(customErrorToText);
24+
return customErrors.map(error => {
25+
return { message: customErrorToText(error) };
26+
});
2527
}
2628

2729
return customErrors.map(customErrorToStructure);

0 commit comments

Comments
 (0)