Skip to content

refactor: Turn send errors into ArgumentError in one place - #212

Merged
slatecipher merged 1 commit into
mainlinefrom
refactor/argument-guard
Dec 4, 2026
Merged

slatecipher merged 1 commit into
mainlinefrom
refactor/argument-guard

Conversation

@slatecipher

Copy link
Copy Markdown
Owner

What and why

The builder turned serialization and encoding errors into ArgumentError in three places: the _converting helper and two inline try blocks in _dump_json and _encode_json. This replaces them with one context manager, _guard_argument, so the next change to how these errors are reported happens in one place.

  • _guard_argument takes what follows the parameter's name in the message (such as "as JSON") and an optional hint.
  • It catches ValueError, which covers PydanticSerializationError and UnicodeDecodeError.
  • No behavior changes: the error messages are the same.

feat/dump-options builds on this change, so this one should merge first.

Testing

  • make check passes: lint, type checks, and 390 tests with the coverage gate.
  • The existing tests for unserializable values, NaN, and non-ASCII headers pass unchanged, which confirms the messages didn't change.

🤖 Generated with Claude Code

- Replace _converting and the two inline try blocks in _dump_json and
  _encode_json with one context manager, _guard_argument, which takes what
  follows the parameter's name ("as JSON") and a hint for the message.
- Catch ValueError, which covers PydanticSerializationError and
  UnicodeDecodeError.
- No behavior changes: the error messages are the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@slatecipher slatecipher added the refactor Code restructuring without intended behavior change label Dec 4, 2026
@slatecipher slatecipher self-assigned this Dec 4, 2026
@slatecipher
slatecipher merged commit 9fe58f1 into mainline Dec 4, 2026
8 checks passed
@slatecipher
slatecipher deleted the refactor/argument-guard branch December 4, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code restructuring without intended behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant