Skip to main content

Utilities API Documentation

Package: @alt-stack/zod-error

zodErrorToString

function zodErrorToString(error: ZodError): string;

Formats every Zod issue as path: message, joining nested path segments with . and issues with ; . When issue.path is empty, the path is (root). An error with no issues produces an empty string.

The function does not include the issue code or rejected input in the string.

zodErrorToStructuredLog

function zodErrorToStructuredLog(
error: ZodError,
input?: unknown,
): StructuredLogError;

Builds a new object from the Zod issues. The input property is omitted when the second argument is undefined; otherwise it is included without cloning or redaction.

StructuredLogError

interface StructuredLogError {
type: "ZodValidationError";
message: string;
issueCount: number;
issues: Array<{
path: string;
message: string;
code: string;
}>;
input?: unknown;
}
PropertySource and behavior
typeconstant "ZodValidationError" discriminator
messageoutput of zodErrorToString(error)
issueCounterror.issues.length
issuesone new entry for every Zod issue, in the original order
issues[].pathdot-joined issue path, or (root) for an empty path
issues[].messageZod's issue message
issues[].codeZod's issue code
inputoptional caller-provided value, included only when not undefined

Because input is unknown, the type does not provide privacy or serialization guarantees. Validate or redact it before logging.