Skip to content

feat(errlanes): enum-level shared rejection code - #279

Merged
bodymindarts merged 2 commits into
mainfrom
feat/errlanes-shared-rejection-code
Oct 15, 2026
Merged

bodymindarts merged 2 commits into
mainfrom
feat/errlanes-shared-rejection-code

Conversation

@bodymindarts

@bodymindarts bodymindarts commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Implements §1 of the handoff handoff-errlanes-shared-rejection-code-and-unique-key-ensure (es-entity-dev space).

  • #[rejection(code, description, level)] on an enum is the default for every variant without its own code / code_and_level_from / delegate.
  • Code type: one variant per distinct code (named after the enum); CODES lists a shared code once.
  • Lift arms under a shared-code enum take the enum's code.
  • Compile errors: unused shared code, empty enum, with code_prefix, variant description under a shared code.
  • #[rejection(from)] on several variants was already allowed (one From per variant); now tested.
  • README section "One code, several causes" with both lana examples as doc-tests (local stand-ins).

Decisions (handoff §4), all recommended options taken:

  • D1: recommended option taken (empty enum with code is a compile error)
  • D5: recommended option taken (lockstep 0.20.0 with PR 2; no version bump here)

Deviations: the handoff asks for a book mirror in an "errlanes chapter", but the book has no errlanes chapter, so only the README (the crate docs) is updated. An explicit code_and_level_from counts as declaring its own code. No CHANGELOG edit (git-cliff generates it from this title).

Pre-existing: cargo clippy --all-targets -D warnings reports lints in untouched errlanes tests (codes.rs, lift_into.rs, lift_newtype.rs, lift_struct.rs).

🤖 Generated with Claude Code


Note

Medium Risk
Changes proc-macro code generation for rejection metadata and lift/catalogue behavior; mistakes could mis-report API error codes, though coverage is strong and misuse is mostly caught at compile time.

Overview
Adds enum-level #[rejection(code, description, level)] on Rejection derives so every variant without its own code, delegate, or code_and_level_from reports the same rejection code (and shared description/level, with per-variant level still allowed).

The derive emits a single code-type variant named after the enum for that shared string, deduplicates it in CODES, and does not auto-forward lift metadata from source variants when shared code applies—lifted arms use the family code instead. Variants that keep their own code or delegate unchanged can mix with shared-code variants.

Compile-time guards reject unused enum-level code, code on empty enums, code together with code_prefix, per-variant description under shared code, and a self-coded variant whose name matches the enum (shared code owns the enum-named code variant).

Docs add a README “One code, several causes” section; trybuild compile-fail cases and integration tests cover catalogue shape, display/source, lift, compose, and mixed delegate/shared families.

Reviewed by Cursor Bugbot for commit 5c039ba. Bugbot is set up for automated code reviews on this repo. Configure here.

`#[rejection(code = .., description = ..)]` on an enum is the code,
description and level of every variant that declares neither its own
`code`, `code_and_level_from` nor `delegate`. The generated code type gets
one variant per distinct code, named after the enum, so `CODES`/`ALL` list a
shared code once. A lift arm under a shared-code enum takes the enum's code
rather than forwarding the source case's, because forwarding only applies
when the destination has no locally declared code.

Compile errors: shared code unused (every variant declares its own), on an
enum with no variants, next to `code_prefix`, or a variant that takes the
shared code declaring its own `description`.

`#[rejection(from)]` on several variants already emitted one `From` per
variant; it is now covered by a test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5dc0480. Configure here.

Comment thread errlanes-derive/src/rejection.rs
The shared code's variant in the generated code type is named after the
enum. The clash check looked at the variants that take the shared code,
which emit no code variant of their own, and missed the ones that do: a
variant with its own `code`, `delegate` or `code_and_level_from` named like
the enum produced a second identical code variant and a derive output that
did not compile. Reject that case with a clear error, and allow a shared-code
variant named like its enum.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@bodymindarts
bodymindarts merged commit 26679d6 into main Oct 15, 2026
6 checks passed
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