Skip to content

Commit

Permalink
report description in more compact form
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Nov 14, 2023
1 parent 4d63cc4 commit 5cbc291
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ export function reportErrors(
): string {
const formattedErrors = errors.map(
({ key, receivedValue, error, defaultUsed, defaultValue }) => {
const message: string[] = [`[${yellow(key)}]:`];
let title = `[${yellow(key)}]:`;

const desc = schemas[key]?.description;
if (desc) {
title += ` ${desc}`;
}

const message: string[] = [title];

if (error instanceof ZodError) {
const { formErrors, fieldErrors } = error.flatten();
Expand Down Expand Up @@ -80,14 +87,6 @@ export function reportErrors(
);
}

const desc = schemas[key]?.description;
if (desc) {
message.push("");
message.push(
`Description of [${yellow(key)}]: ${schemas[key]!.description}`,
);
}

return message.map((l) => indent(l, 2)).join("\n");
},
);
Expand Down

0 comments on commit 5cbc291

Please sign in to comment.