fix: normalize object validation errors#144
Open
0xpolarzero wants to merge 1 commit into
Open
Conversation
b2f746d to
3fd525c
Compare
This was referenced May 22, 2026
This was referenced May 22, 2026
3fd525c to
0217d7b
Compare
0217d7b to
85d238a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Normalize validation errors for structured command input.
CLI argv parsing already turns Zod failures into incur's standard
VALIDATION_ERRORshape withfieldErrors. HTTP-style execution (split) and MCP-style execution (flat) were using raw Zod.parse(), so the same kind of invalid command input could come back as a genericUNKNOWNerror instead.Issue
Command.execute()has three parsing modes:argv: CLI tokens.split: positional args from argv, options from an object. This is used by HTTP command routes.flat: one object split into args/options. This is used by MCP-style calls.Before this PR, only
argvwent through incur's validation wrapper. The object-based modes called Zod directly:That meant bad structured input like this:
did not produce the same structured field error as CLI input.
Tests failing before fix
src/Cli.test.tsadds direct executor coverage for both object-based modes.For
splitandflat, invalid command input now returns:src/Cli.test.tsalso guards the boundary: if user code throws a Zod error insiderun(), it is still treated as a handler error, not as command input validation.Expected result:
Fix
Parser.zodParse()is exported so the command executor can reuse the existing Zod-to-ValidationErrorconversion.Command.execute()now uses that wrapper for:splitoptions.flatargs.flatoptions.The change is intentionally narrow: only command input parsing is normalized. Handler-thrown Zod errors still follow the normal handler error path.