fix: surface validation issues in update and delete error output#7
Open
chrisstrahl wants to merge 1 commit into
Open
fix: surface validation issues in update and delete error output#7chrisstrahl wants to merge 1 commit into
chrisstrahl wants to merge 1 commit into
Conversation
When collection.update() rejects a write, the library returns both
result.error and result.issues (an array of {code, message, field,
severity}), but the update command printed only error.message
("Validation failed on update") and discarded the issues in both text
and --format json output. That leaves the user with no way to see
*which* field failed or why. The create command already surfaced
issues; update and delete did not.
- Move formatIssue from create.ts into utils.ts and share it.
- update: include `issues` in JSON error output and print them as
indented lines in text output, matching create's behavior.
- delete: same defensive passthrough (no library code path returns
issues on delete today, but the output contract now matches).
- Add a strict-validation test fixture (default_validation: error),
since the default "warn" level never rejects updates.
- Add tests for update issue output, plus regression tests for
create's existing issue output.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
When
collection.update()rejects a write, the library returns bothresult.errorandresult.issues(an array of{code, message, field, severity}), but theupdatecommand prints onlyerror.message("Validation failed on update") and discards the issues in both text and--format jsonoutput.That makes validation failures undiagnosable from the CLI — you can't see which field failed or why. In practice this hid a real library bug for a while (see callumalpass/mdbase#3, where a generated date field caused every
updateto fail with nothing but the one-line message).Before:
After:
and in JSON:
{ "error": { "code": "validation_failed", "message": "Validation failed on update" }, "issues": [ { "code": "number_too_large", "message": "Integer \"rating\" is too large (10 > 5)", "field": "rating", "severity": "error" } ] }Changes
update: includeissuesin JSON error output and print them as indented lines in text output — same formatcreatealready uses.delete: same passthrough for output-contract parity. (No library code path returnsissueson delete today, so this is defensive; happy to drop it if you'd rather not carry the dead branch.)utils.ts:formatIssuemoved here fromcreate.tsso all three commands share it. No behavior change forcreate.test/fixtures/strict-collectionfixture withdefault_validation: error(the defaultwarnlevel never rejects updates, so the existing fixture can't trigger this path). Two new update tests (JSON + text), plus regression tests pinningcreate's existing issue output. Fixture's.mdbase/cache dir is gitignored.Testing
tscclean.🤖 Generated with Claude Code