Is there a way to pretty print Problems? #914
-
I was looking at https://arktype.io/docs/#your-first-type the first example, and it's got some killer error displays. It looks like it depends on an internal import { stringify } from "arktype/internal/utils/serialize.js" Is there an equivalent? I'm looking to use ArkType as data validation when using Vite's dynamic import, and was hoping to have prettier output. Thanks for the neat library! |
Beta Was this translation helpful? Give feedback.
Answered by
ssalbdivad
Mar 14, 2024
Replies: 1 comment 2 replies
-
Shortly after creating the issue, I explored the if (decodedType.problems) {
// data has problems
console.log("problems", decodedType.problems);
decodedType.problems.forEach((problem) => {
console.error(
`\`${problem.path.join(".")}\`.\n[${problem.code}] ${problem.reason}`
);
});
} else {
// data is valid
const data = decodedType.data;
console.log(data);
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, this is built in! What you're looking for is
problems.summary
.Each problem also has a builtin description as its
toString
implementation, so if you do something likeproblems.join("\n")
that should work as well.