Skip to content

fix: surface validation issues in update and delete error output#7

Open
chrisstrahl wants to merge 1 commit into
callumalpass:mainfrom
chrisstrahl:surface-validation-issues
Open

fix: surface validation issues in update and delete error output#7
chrisstrahl wants to merge 1 commit into
callumalpass:mainfrom
chrisstrahl:surface-validation-issues

Conversation

@chrisstrahl

Copy link
Copy Markdown

Problem

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 prints only error.message ("Validation failed on update") and discards the issues in both text and --format json output.

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 update to fail with nothing but the one-line message).

Before:

$ mdbase update hello.md -f rating=10
error: Validation failed on update

After:

$ mdbase update hello.md -f rating=10
error: Validation failed on update
  error field rating: Integer "rating" is too large (10 > 5) [number_too_large]

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: include issues in JSON error output and print them as indented lines in text output — same format create already uses.
  • delete: same passthrough for output-contract parity. (No library code path returns issues on delete today, so this is defensive; happy to drop it if you'd rather not carry the dead branch.)
  • utils.ts: formatIssue moved here from create.ts so all three commands share it. No behavior change for create.
  • Tests: new test/fixtures/strict-collection fixture with default_validation: error (the default warn level never rejects updates, so the existing fixture can't trigger this path). Two new update tests (JSON + text), plus regression tests pinning create's existing issue output. Fixture's .mdbase/ cache dir is gitignored.

Testing

  • New update tests written first and confirmed failing against the old code (issues absent from both formats), then passing with the fix.
  • Full suite: 269/269 passing, tsc clean.

🤖 Generated with Claude Code

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>
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