Skip to content

chore(provider): format zod errors compactly for run.errors#86

Open
coletebou wants to merge 1 commit into
openclaw:mainfrom
coletebou:pr/zod-format
Open

chore(provider): format zod errors compactly for run.errors#86
coletebou wants to merge 1 commit into
openclaw:mainfrom
coletebou:pr/zod-format

Conversation

@coletebou
Copy link
Copy Markdown

Summary

When reviewOutputSchema.parse() (or any of the 16 provider-output parses) throws on bad model output, the error embeds the entire ~1.5KB zod issue blob in run.errors[].message. Operators tailing a log can't easily see what went wrong.

This PR wraps every provider-output parse with a small parseOrThrow helper that emits one-line summaries:

codex review: schema validation failed: findings[0].category="quality" (invalid_value, expected one of bug,security,performance,concurrency,...)

Three issues max, then (+N more). Values truncated to 80 chars.

Files

  • src/provider.ts — new helpers (formatZodPath, previewZodValue, lookupAtPath, formatZodIssue, formatZodError, parseOrThrow); 16 .parse(output) call sites swapped to parseOrThrow(...) with descriptive labels (codex map, codex review, …, pi revalidate)
  • src/provider.test.ts — 6 new cases (4 formatter, 2 wrapper)

The Pi provider added in #50 had four un-wrapped .parse(output) calls; this PR wraps those too, so git grep ".parse(output)" src/ returns empty after merge.

Why

Run 20260517T190759-3c9e9e had 26 zod-throw errors. Each one's message in run.errors[].message was 1.5KB of nested JSON. After this PR the operator-relevant info (path + sample bad value) is on a single line.

Validation

  • pnpm format:check — clean
  • pnpm typecheck — clean
  • pnpm lint — clean
  • pnpm build — clean
  • pnpm test — 547 passed, 1 skipped (+6 new)

Coordination

Layered cleanly on the safeparse-partition PR — if that one lands first, this PR's formatZodError becomes the drop-reason rendering. They merge in either order.

Replace raw ZodError JSON blobs in run.errors[].message with one-line
path=value (code, expected ...) summaries.

Adds formatZodIssue / formatZodError helpers and a parseOrThrow wrapper.
Replaces the 16 schema.parse(output) call sites across codex, opencode,
acpx, and grok providers (map / review / fix / revalidate). Behavior is
unchanged: still throws ClawpatchError with code 'malformed-output' and
exit code 8 — only the message text is compact.

Bad values for enum mismatches are looked up from the original input via
the issue path (zod 4 omits 'received' for invalid_value).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant