Skip to content

fix(operations): map edit_note write failures to WRITE_FAILED - #116

Merged
AlexMost merged 1 commit into
mainfrom
fix/edit-note-write-failed-code
Aug 28, 2026
Merged

AlexMost merged 1 commit into
mainfrom
fix/edit-note-write-failed-code

Conversation

@AlexMost

Copy link
Copy Markdown
Owner

What

An fs write failure inside edit_note (disk full, permission lost, locked file) escaped FsVaultWriter as a bare Node Error with no code. toToolErrorResponse renders such an error through its plain { message } branch, so a client branching on error codes got nothing to branch on — a direct ADR-0003 violation. The identical failure through set_property already yielded WRITE_FAILED.

Changes

  • FsVaultWriter — both writeFile calls now go through a writeRaw helper that maps failures to ToolHandlerError('WRITE_FAILED', …) with details.path, mirroring FsVaultProvider.editFrontmatter.
  • FsVaultProvider.createNote — the both-identifiers-missing guard threw a code-less new Error(...). It now throws INVALID_ARGUMENT via invalidArgument, so the provider contract does not rely on the tool-level XOR shielding it.

Tests

Five new assertions, each verified to fail against the unpatched source:

  • replaceInNote and replaceFullBody map an injected failing writeFile to WRITE_FAILED (ENOSPC / EACCES).
  • Two edit_note-level cases drive the real FsVaultWriter through registerTool(...).handler(...) and assert the client-visible payload carries code: 'WRITE_FAILED' — covering the mapping and the rendering together.
  • createNote({}) now asserts the code and field instead of only the message string.

npm test (1292 passing), npm run lint, and npm run typecheck all pass.

Closes #113

🤖 Generated with Claude Code

An fs write failure inside `edit_note` (disk full, permission lost,
locked file) escaped `FsVaultWriter` as a bare Node `Error`, which
`toToolErrorResponse` renders through its code-less branch — a client
branching on error codes got nothing to branch on, in violation of
ADR-0003. The same failure through `set_property` already yielded
`WRITE_FAILED`.

Wrap both `writeFile` calls in a `writeRaw` helper that maps failures to
`ToolHandlerError('WRITE_FAILED', …)`, matching
`FsVaultProvider.editFrontmatter`. Also give `createNote`'s
both-identifiers-missing guard a code, so the provider contract does not
rely on the tool-level XOR shielding it.

Closes #113

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@AlexMost
AlexMost merged commit 57e1ede into main Aug 28, 2026
2 checks passed
@AlexMost
AlexMost deleted the fix/edit-note-write-failed-code branch August 28, 2026 16:38
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.

edit_note write failure escapes as a bare Error without a code (ADR-0003 violation)

1 participant