Skip to content

feat(workspace)!: [#2454] mark public error enums non_exhaustive before first publish - #2568

Merged
josecelano merged 26 commits into
torrust:developfrom
josecelano:2454-1669-mark-public-error-enums-non-exhaustive
Oct 20, 2026
Merged

josecelano merged 26 commits into
torrust:developfrom
josecelano:2454-1669-mark-public-error-enums-non-exhaustive

Conversation

@josecelano

Copy link
Copy Markdown
Member

Summary

Closes #2454. Part of EPIC #1669.

58 public error enums in 16 publishable packages now carry #[non_exhaustive], so adding a variant later is not a breaking change for their consumers. Two enums stay exhaustive on purpose, because their variants select a recovery action: torrust_tracker_events::receiver::RecvError (Closed ends a listener, Lagged continues) and torrust_tracker_udp_protocol::request::RequestParseError (Sendable replies to the client, Unsendable drops the request). A wildcard arm there would silently choose an action for a variant nobody designed for, so a new variant must be a deliberate breaking change. The maintainer decided this during the T1 review, and the PR records it as an amendment of ADR 20261005145329, in the EPIC #1669 Pre-publish API checklist, and in the handle-errors-in-code skill. torrust_tracker_configuration::Error::Infallible, a never-constructed placeholder variant, is removed.

Four workspace crates are already on crates.io at 3.0.0: torrust-tracker (11 enums marked), torrust-tracker-configuration (2), torrust-tracker-primitives (2), and torrust-tracker-test-helpers (none). The first three must be published with a semver-major bump, as EPIC checklist item 4 states; this PR does not edit versions. Every other package is unpublished, so its first publish carries the attribute.

Changes

  • Inventory error-enum-inventory.md in the spec folder: 60 public error enums found with rustdoc JSON on the nightly toolchain and cross-checked against rg; per-enum variants, derives and downstream matches; per-crate completion; derive findings (record only, no derive changed); the publish bump per crate.
  • One feat(<package>)!: [#2454] mark public error enums non_exhaustive commit per package, in dependency order. The eight downstream exhaustive match sites that the attribute forces get a wildcard arm in the commit of the package whose enum forces it, so every commit builds: http-core (TrackerCoreError), rest-api-runtime-adapter (PeerKeyError, mapped to AuthKeyError::Database, the only generic failure variant), udp-server (four nested matches, mapped to ErrorKind::InternalServer), axum-rest-api-server (the Database arm became the _ arm, same response), and the tracker_client binary (reported as a runtime_failure, through a helper extracted from the Other arm with unchanged output).
  • docs(events) and docs(udp-protocol) commits add the doc comments for the two exhaustive enums.
  • refactor(configuration)! removes Error::Infallible.
  • ADR 20261005145329 amended, docs/adrs/index.md, the handle-errors-in-code skill, and the EPIC Overhaul: Packages #1669 spec (checklist item 1, a link to the inventory's per-crate completion record, log entries) updated; mpsc added to project-words.txt.
  • Issue spec Mark public error enums #[non_exhaustive] before first publish #2454 updated, with manual-verification-evidence.md, agent-review-reports.md, and evidence/.

udp_server::event::ErrorKind is out of scope: it matches the name filter but is not an error type.

Validation

  • linter all and the other pre-commit checks passed on every commit; the pre-push checks passed on the final tree (nightly format, check, docs and library docs, and the full stable test suite), output in evidence/pre-push-output.txt.
  • cargo check --workspace --all-targets --all-features passes on each of the branch's commits, checked in a scratch worktree on the stable toolchain.
  • Manual check M1: a scratch crate outside the workspace depends by path on torrust-tracker-primitives, torrust-tracker-configuration and torrust-tracker-events. An exhaustive match on IdConversionError and on configuration::Error fails with E0004, the same matches with a _ arm compile, and an exhaustive match on RecvError still compiles. Details and outputs are in manual-verification-evidence.md and evidence/m1/.
  • An independent Task Reviewer pass found no defect in the Rust changes; its process findings are addressed (agent-review-reports.md).

No temporary local-only patches are part of this branch or of the verification.

Notes for review

josecelano and others added 24 commits October 19, 2026 20:18
…select a recovery action

Amend ADR 20261005145329 after the maintainer's T1 review: an enum whose
variants select different recovery actions stays exhaustive, with a doc
comment saying why. Update the EPIC torrust#1669 checklist item 1 and the
handle-errors-in-code skill, and record the decision in the torrust#2454 spec.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 19, 2026 19:56
@josecelano
josecelano requested a review from a team as a code owner October 19, 2026 19:56
@josecelano
josecelano requested a review from da2ce7 October 19, 2026 19:56

Copilot AI 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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

No open issues 🎉

What changed in this PR

Marks public error enums as #[non_exhaustive] across publishable workspace crates (and updates downstream matches + documentation/spec evidence) so future error-variant additions aren’t breaking changes, except for two intentionally-exhaustive control-flow enums.

Changes:

  • Add #[non_exhaustive] to many public error enums across crates and binaries.
  • Update impacted downstream match sites with wildcard arms and adjust one CLI error-reporting path to handle future variants.
  • Update ADR/EPIC/spec/docs and add inventory + verification evidence artifacts.
File Description
src/​container.rs Mark root crate public error enum as #[non_exhaustive].
src/​console/​profiling.rs Mark profiling executable error enum as #[non_exhaustive].
src/​bootstrap/​persistence.rs Mark persistence requirement error enum as #[non_exhaustive].
src/​bootstrap/​jobs/​udp_tracker.rs Mark UDP tracker bootstrap job error enum as #[non_exhaustive].
src/​bootstrap/​jobs/​tracker_core.rs Mark tracker-core jobs error enum as #[non_exhaustive].
src/​bootstrap/​jobs/​tracker_apis.rs Mark tracker APIs bootstrap job error enum as #[non_exhaustive].
src/​bootstrap/​jobs/​http_tracker.rs Mark HTTP tracker bootstrap job error enum as #[non_exhaustive].
src/​bootstrap/​jobs/​health_check_api.rs Mark health check API bootstrap job error enum as #[non_exhaustive].
src/​bootstrap/​config.rs Mark config-loading error enum as #[non_exhaustive].
src/​bootstrap/​app.rs Mark pre-jobs bootstrap error enum as #[non_exhaustive].
src/​app.rs Mark startup completion error enum as #[non_exhaustive].
project-words.txt Add mpsc to project dictionary.
packages/​udp-server/​src/​server/​processor.rs Mark UDP processor error enum as #[non_exhaustive].
packages/​udp-server/​src/​server/​mod.rs Mark UDP server error enum as #[non_exhaustive].
packages/​udp-server/​src/​event.rs Add wildcard mappings for newly non-exhaustive upstream errors.
packages/​udp-server/​src/​error.rs Mark UDP server error enum as #[non_exhaustive].
packages/​udp-protocol/​src/​request.rs Document why RequestParseError intentionally remains exhaustive.
packages/​udp-core/​src/​services/​scrape.rs Mark UDP scrape service error enum as #[non_exhaustive].
packages/​udp-core/​src/​services/​announce.rs Mark UDP announce service error enum as #[non_exhaustive].
packages/​udp-core/​src/​connection_cookie.rs Mark connection cookie error enum as #[non_exhaustive].
packages/​tracker-core/​src/​statistics/​persisted/​mod.rs Mark persisted stats error enum as #[non_exhaustive].
packages/​tracker-core/​src/​error.rs Mark multiple core error enums as #[non_exhaustive].
packages/​tracker-core/​src/​databases/​error.rs Mark database error enum as #[non_exhaustive].
packages/​tracker-core/​src/​container.rs Mark core container error enum as #[non_exhaustive].
packages/​tracker-core/​src/​authentication/​key/​peer_key.rs Mark peer-key parse error enum as #[non_exhaustive].
packages/​tracker-core/​src/​authentication/​key/​mod.rs Mark auth key error enum as #[non_exhaustive].
packages/​tracker-client/​src/​udp/​mod.rs Mark client-lib UDP error enum as #[non_exhaustive].
packages/​tracker-client/​src/​http/​client/​mod.rs Mark client-lib HTTP client error enum as #[non_exhaustive].
packages/​rest-api-runtime-adapter/​src/​v1/​adapters/​auth_key.rs Add wildcard mapping for newly non-exhaustive PeerKeyError.
packages/​rest-api-protocol/​src/​v1/​context/​whitelist/​resources/​whitelist.rs Mark protocol whitelist error enum as #[non_exhaustive].
packages/​rest-api-protocol/​src/​v1/​context/​auth_key/​resources/​auth_key.rs Mark protocol auth-key error enum as #[non_exhaustive].
packages/​rest-api-client/​src/​v1/​client.rs Mark REST API client error enum as #[non_exhaustive].
packages/​rest-api-client/​src/​connection_info.rs Mark origin parsing error enum as #[non_exhaustive].
packages/​primitives/​src/​peer.rs Mark primitives parse/conversion error enums as #[non_exhaustive].
packages/​http-protocol/​src/​v1/​services/​peer_ip_resolver.rs Mark peer-IP resolution error enum as #[non_exhaustive].
packages/​http-protocol/​src/​v1/​responses/​scrape/​deserialization.rs Mark bencode parse error enum as #[non_exhaustive].
packages/​http-protocol/​src/​v1/​requests/​scrape.rs Mark scrape query parse error enum as #[non_exhaustive].
packages/​http-protocol/​src/​v1/​requests/​announce.rs Mark announce query parse error enum as #[non_exhaustive].
packages/​http-protocol/​src/​v1/​query.rs Mark query parse error enum as #[non_exhaustive].
packages/​http-protocol/​src/​v1/​auth.rs Mark auth extraction error enum as #[non_exhaustive].
packages/​http-protocol/​src/​percent_encoding.rs Mark peer-id conversion error enum as #[non_exhaustive].
packages/​http-core/​src/​services/​scrape.rs Mark HTTP scrape service error enum as #[non_exhaustive].
packages/​http-core/​src/​services/​error_mapping.rs Add wildcard mapping for newly non-exhaustive TrackerCoreError.
packages/​http-core/​src/​services/​announce.rs Mark HTTP announce service error enum as #[non_exhaustive].
packages/​events/​src/​receiver.rs Document why RecvError intentionally remains exhaustive.
packages/​configuration/​src/​validator.rs Mark semantic validation error enum as #[non_exhaustive].
packages/​configuration/​src/​lib.rs Mark config error enum as #[non_exhaustive]; remove placeholder Infallible variant.
packages/​axum-server/​src/​tls.rs Mark TLS bootstrap error enum as #[non_exhaustive].
packages/​axum-rest-api-server/​src/​v1/​context/​torrent/​handlers.rs Mark query param error enum as #[non_exhaustive].
packages/​axum-rest-api-server/​src/​v1/​context/​auth_key/​handlers.rs Use wildcard arm for newly non-exhaustive protocol AuthKeyError.
packages/​axum-rest-api-server/​src/​server.rs Mark server lifecycle error enum as #[non_exhaustive].
packages/​axum-http-server/​src/​server.rs Mark HTTP server lifecycle error enum as #[non_exhaustive].
packages/​axum-health-check-api-server/​src/​server.rs Mark health-check server error enum as #[non_exhaustive].
packages/​axum-health-check-api-server/​src/​environment.rs Mark environment error enum as #[non_exhaustive].
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​manual-verification-evidence.md Add recorded manual verification scenario M1 evidence.
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​pre-push-output.txt Add stored pre-push output artifact.
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​m1/​wildcard_primitives.txt Store M1 output artifact (wildcard primitives case).
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​m1/​wildcard_configuration.txt Store M1 output artifact (wildcard configuration case).
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​m1/​toolchain.txt Store M1 toolchain artifact.
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​m1/​src/​wildcard_primitives.rs Store M1 source artifact (wildcard primitives example).
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​m1/​src/​wildcard_configuration.rs Store M1 source artifact (wildcard configuration example).
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​m1/​src/​exhaustive_recv_error.rs Store M1 source artifact (exhaustive control case).
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​m1/​src/​exhaustive_primitives.rs Store M1 source artifact (exhaustive primitives failure case).
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​m1/​src/​exhaustive_configuration.rs Store M1 source artifact (exhaustive configuration failure case).
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​m1/​exhaustive_recv_error.txt Store M1 output artifact (exhaustive control case).
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​m1/​exhaustive_primitives.txt Store M1 output artifact (exhaustive primitives failure).
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​m1/​exhaustive_configuration.txt Store M1 output artifact (exhaustive configuration failure).
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​evidence/​m1/​Cargo.toml.txt Store M1 scratch-crate manifest artifact.
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​error-enum-inventory.md Add inventory of public error enums + decisions and downstream match sites.
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​agent-review-reports.md Add independent task reviewer report record.
docs/​issues/​open/​2454-1669-mark-public-error-enums-non-exhaustive/​ISSUE.md Update spec status, decisions, task completion, ACs, and evidence links.
docs/​issues/​open/​1669-overhaul-packages/​EPIC.md Update checklist to include exhaustive-enum exception + link to inventory record.
docs/​adrs/​index.md Update ADR index entry to mention exhaustive-enum exception.
docs/​adrs/​20261005145329_return_result_only_for_concretely_fallible_public_apis.md Amend ADR to document exception for control-flow recovery-action enums.
console/​tracker-client/​src/​console/​clients/​unified/​app.rs Mark console unified client error enum as #[non_exhaustive].
console/​tracker-client/​src/​console/​clients/​udp/​mod.rs Mark console UDP client error enum as #[non_exhaustive].
console/​tracker-client/​src/​console/​clients/​http/​mod.rs Mark console HTTP client error enum as #[non_exhaustive].
console/​tracker-client/​src/​console/​clients/​checker/​error.rs Mark checker app error enum as #[non_exhaustive].
console/​tracker-client/​src/​console/​clients/​checker/​config.rs Mark checker configuration error enum as #[non_exhaustive].
console/​tracker-client/​src/​console/​clients/​checker/​checks/​health.rs Mark checker health check error enum as #[non_exhaustive].
console/​tracker-client/​src/​bin/​tracker_client.rs Add wildcard handling for new non-exhaustive variants in CLI error reporting.
.github/​skills/​dev/​rust-code-quality/​handle-errors-in-code/​SKILL.md Update skill guidance to include exhaustive-enum exception.

Review effort: Lite

@josecelano

Copy link
Copy Markdown
Member Author

ACK 24276fb

@josecelano
josecelano merged commit e1bf6fe into torrust:develop Oct 20, 2026
47 checks passed
josecelano added a commit that referenced this pull request Oct 20, 2026
…ssues/closed

2e6b5d8 chore(issues): archive closed issue #2454 spec to docs/issues/closed (Jose Celano)

Pull request description:

  Archives the spec for issue #2454 (closed on GitHub, implemented by PR #2568, merged 2026-10-20) from `docs/issues/open/` to `docs/issues/closed/`, and marks #2454 as done in EPIC #1669.

  - Verified issue #2454 is `CLOSED` on GitHub.
  - Moved the spec folder, including the inventory, the manual verification evidence, the review report, and `evidence/`. Updated the frontmatter (`status: done`, `spec-path`, `last-updated-utc`), the `issue-spec` path of the evidence file, and the inventory's link to the EPIC.
  - Ticked the two closing workflow checkpoints. The checkpoint "Reviewer validated acceptance criteria and updated checkboxes" stays not ticked, because da2ce7 never reviewed PR #2568; the spec's progress log says so.
  - EPIC #1669: ticked #2454, set its table row to `DONE`, repointed the three links to the archived paths, and added a log entry that records the semver-major bump the next publish of `torrust-tracker`, `torrust-tracker-configuration` and `torrust-tracker-primitives` needs.
  - Repointed the frontmatter link in `docs/pr-reviews/pr-2456-review/PR-REVIEW.md`, so the frontmatter validator still finds the spec.
  - Pre-commit checks passed.

ACKs for top commit:
  josecelano:
    ACK 2e6b5d8

Tree-SHA512: 9b83fb47970fa7d3827130c128bdf4af9338076942ca6f4342526984cfd7f9832ff290d4ff8f83e8023b20a60a0277d62e6552ef54513c0c66b8d36d2414bc46

@da2ce7 da2ce7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a post-merge review of the change from #2568 as it stands at a94c3ced8 on the default branch.

What still runs: all 58 #[non_exhaustive] attributes are in place, RecvError and RequestParseError are still exhaustive with their doc comments, and configuration::Error::Infallible is gone. The eight wildcard arms the change added are all live: protocol_error_from_tracker_core_error (packages/http-core/src/services/error_mapping.rs:18), map_peer_key_error (packages/rest-api-runtime-adapter/src/v1/adapters/auth_key.rs:80), the four nested arms of From<Error> for ErrorKind (packages/udp-server/src/event.rs:133, :139, :146, :149), the _ arm of add_auth_key_handler (packages/axum-rest-api-server/src/v1/context/auth_key/handlers.rs:46) and the unknown arm of the tracker_client binary (console/tracker-client/src/bin/tracker_client.rs:28). None of them is reachable today, because every current variant has its own arm, including the two variants added since (UdpAnnounceError::InvalidAnnounceRequest in 594c21b and app::Error::TtyRefusal in 36607df). Because these crates build together, a variant added later in a sibling crate now lands in one of these wildcards without a compile error, so the points below are about what such a variant would get.

[Minor] packages/udp-server/src/event.rs:139 and :149 (and the inner arms at :133 and :146) map an unknown UdpAnnounceError, UdpScrapeError, AnnounceError or ScrapeError to ErrorKind::InternalServer. That chooses an action as well as a label: trigger_udp_error_event publishes this conversion as the UdpError event (packages/udp-server/src/handlers/error.rs:151), and the ban handler counts a client only when the kind is ErrorKind::ConnectionCookie (packages/udp-server/src/banning/event/handler.rs:24). Suppose a later change in udp-core adds a second cookie failure variant to UdpAnnounceError. The workspace builds, requests that hit it are reported as internal server errors, and the client that sends them never reaches the ban threshold. The amendment to ADR 20261005145329 (docs/adrs/20261005145329_return_result_only_for_concretely_fallible_public_apis.md:130-141) keeps an enum exhaustive exactly when its variants select different actions, yet the issue's error enum inventory counted this site among those that only report or convert. Smallest fix: apply the amendment to UdpAnnounceError and UdpScrapeError (drop the attribute, add the doc comment, remove the arms at :139 and :149). Failing that, add a comment on both enums and at the arms saying that a new variant must be classified in From<Error> for ErrorKind, since the compiler no longer asks. 594c21b did add its arm by hand; that check now depends on the author remembering it.

[Minor] console/tracker-client/src/bin/tracker_client.rs:28 writes format!("{unknown:?}"), the Debug text of an unknown app::Error variant, as the message of the stderr record. The client's output contract says that no output carries a secret and that a failed HTTP request is never described by the Debug text of the HTTP library error (console/tracker-client/docs/contracts/tracker-cli-io-contract.md:50-63). The masking in packages/tracker-client/src/http/client/redaction.rs is applied where messages are built and does not reach a Debug dump. Suppose a later variant wraps a reqwest::Error or a tracker URL and gets no arm of its own. A request to http://host:7070/announce/<key> fails, the stderr record carries the key unmasked, and nothing fails to compile. Smallest fix: give the arm a fixed message without the payload, for example report_runtime_failure("unclassified runtime failure").

[Nit] packages/http-core/src/services/error_mapping.rs:19 formats the whole TrackerCoreError, while the other four arms format only the inner source under their own prefix. The outer Display already starts with Tracker core … error: (packages/tracker-core/src/error.rs:28), so a future variant would reach HTTP clients with the failure_reason Tracker error: Tracker core … error: …, the prefix twice. format!("{unknown}") on its own avoids the repetition.

[Nit] packages/events/src/receiver.rs:67-69: TryRecvError, added in 8726ecf, is rightly exhaustive, since the drain helper stops on Empty and Closed and keeps going on Lagged (packages/events/src/drain.rs:120-122). It lacks the doc comment that the ADR asks for so that nobody adds the attribute later (docs/adrs/20261005145329_return_result_only_for_concretely_fallible_public_apis.md:140-141), and the ADR still names only two exhaustive enums (:147-149). The same doc comment that RecvError carries, plus a mention in the ADR, closes this.

Checked and found sound: the 58 attributes match the issue's inventory crate by crate (11 in torrust-tracker, 2 each in torrust-tracker-configuration and torrust-tracker-primitives), and the public error enums added since (FromRequestError, SpawnError, bootstrap::event_flows::Error) carry the attribute too. The attribute changes no runtime behaviour. The doc comments on RecvError and RequestParseError still match how consumers use them, and no Infallible variant remains. map_peer_key_error and the _ arm of add_auth_key_handler answer with the existing generic failure, and PeerKeyError::InvalidKey no longer keeps the key (packages/tracker-core/src/error.rs:123-127). No wildcard over the authentication, request-parsing or persistence error enums grants access: the one over ParseKeyError (packages/axum-http-server/src/v1/extractors/authentication_key.rs:122) rejects the key. Whether each commit of the change builds on its own was not checked.

This branch was previously deployed

1 inactive deployment
coverage — 24276fb5 Deployed Oct 20, 2026 by josecelano via Generate Coverage Report #2626
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.

Mark public error enums #[non_exhaustive] before first publish

3 participants