Skip to content

Error on duplicate and colliding command registrations - #251

Open
johncarmack1984 wants to merge 1 commit into
specta-rs:mainfrom
johncarmack1984:john/115-duplicate-commands
Open

johncarmack1984 wants to merge 1 commit into
specta-rs:mainfrom
johncarmack1984:john/115-duplicate-commands

Conversation

@johncarmack1984

Copy link
Copy Markdown

Closes #115.

What changed

  • export now fails with a clear message when a command is registered more than once, instead of silently generating a bindings object where the last registration wins
  • the check runs on the cased accessor name, so it also catches two differently named commands that collide after function_casing is applied (e.g. my_cmd and myCmd both exporting as myCmd), with a message that names both commands and the colliding accessor
  • regression tests for both cases plus a passing control

Why

commands.myCmd silently binding to whichever registration came last is a correctness trap — the error surfaces it at export time with the exact names involved.

Notes

Two same-named commands in different modules of one crate currently can't even be constructed — the generated __specta__fn__*/__cmd__* helper macros collide at crate root (the same family as #142) — so that scenario is only reachable across crates (e.g. a plugin command clashing with an app one), where this check still catches it. Noted in the test file.

Validation

  • cargo test --all-features (3 new tests)
  • cargo clippy --all-features --all-targets (no warnings)
  • cargo fmt --check

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.

You can put the same command many times

1 participant