Skip to content

feat: allow a boxed error in a transparent field [release] - #58

Merged
Totodore merged 2 commits into
developfrom
derive-transparent-boxed-error
Nov 23, 2026
Merged

Totodore merged 2 commits into
developfrom
derive-transparent-boxed-error

Conversation

@Totodore

Copy link
Copy Markdown
Contributor

Description

  • #[api_error(transparent)] needed the field itself to implement ApiError, so a Box<dyn ApiError + Send + Sync> field needed a hand-written impl.
  • The derive now reaches the error behind a pointer (Box<dyn ApiError>, with or without Send/Sync, and Box<ConcreteError>), through a hidden helper called with method syntax. thiserror does the same for Box<dyn Error> sources.
  • The generated code names the trait as ::api_error::ApiError, so #[derive(api_error::ApiError)] works without importing the trait.
  • thiserror still rejects a Box<dyn ApiError> field as transparent, #[source] or #[from]: such a variant uses #[error("{0}")].
  • The new derive output needs the __private module of the matching api-error: both crates must be published together.
  • The compile error for a transparent field that is not an ApiError now names the helper method.
  • The "Multiple attributes" doctest of ApiError already fails on develop with Rust 1.100 locally; this PR does not touch it.

🤖 Generated with Claude Code

A type that wraps an error whose concrete type cannot be named, such
as the `impl ApiError` a trait method returns, had to write its
`ApiError` impl by hand: `#[api_error(transparent)]` needed the field
itself to implement `ApiError`, and `Box<dyn ApiError>` cannot.

The derive now calls a hidden helper with method syntax, so the
compiler dereferences the field until it finds an `ApiError`. This is
the approach `thiserror` uses for `Box<dyn Error>` sources.

The generated code also names the trait by its full path, so the derive
no longer needs `ApiError` to be in scope.

Assisted-by: Claude Code (claude-fable-5-2)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Totodore Totodore added ai-assisted Written with Claude Code. The create-pr skill sets it; add it by hand on a PR you opened yourself. enhancement New feature or request rust Pull requests that update rust code labels Nov 23, 2026
@Totodore
Totodore marked this pull request as ready for review November 23, 2026 16:24
@Totodore
Totodore requested a review from a team as a code owner November 23, 2026 16:24
@Totodore
Totodore requested review from leoncx and removed request for a team November 23, 2026 16:24
@Totodore
Totodore merged commit 9563bed into develop Nov 23, 2026
10 checks passed
@Totodore
Totodore deleted the derive-transparent-boxed-error branch November 23, 2026 16:24
Totodore added a commit that referenced this pull request Nov 23, 2026
The squashed commit of #58 landed without the `[release]` marker, so
no release PR was opened for it. This commit carries the marker to
trigger one; the diff is comment-only.

Assisted-by: Claude Code (claude-fable-5-2)

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted Written with Claude Code. The create-pr skill sets it; add it by hand on a PR you opened yourself. enhancement New feature or request rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant