Skip to content

Commit

Permalink
Add comment to message getter noting that it returns JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronhipple committed Jan 7, 2025
1 parent f7ad261 commit c2750a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions deno/lib/ZodError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ export class ZodError<T = any> extends Error {
override toString() {
return this.message;
}

/**
* message returns the .issues field as a pretty-printed JSON string, NOT necessarily a human-readable message.
*/
override get message() {
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
}
Expand Down
4 changes: 4 additions & 0 deletions src/ZodError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ export class ZodError<T = any> extends Error {
override toString() {
return this.message;
}

/**
* message returns the .issues field as a pretty-printed JSON string, NOT necessarily a human-readable message.
*/
override get message() {
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
}
Expand Down

0 comments on commit c2750a0

Please sign in to comment.