Skip to content

chore: rust-idiomatic compliance pass across M3 + M2 modules#21

Open
brunota20 wants to merge 1 commit into
docs/tutorial-first-module-bleu-848from
chore/rust-idiomatic-pass
Open

chore: rust-idiomatic compliance pass across M3 + M2 modules#21
brunota20 wants to merge 1 commit into
docs/tutorial-first-module-bleu-848from
chore/rust-idiomatic-pass

Conversation

@brunota20

Copy link
Copy Markdown
Collaborator

Summary

QA pass against the team's `rust-idiomatic` skill ahead of M4 work. Mostly mechanical (em-dash purge, missing lint attribute) with a handful of small typing improvements where the rule asked for thiserror enums.

Stacked on top of the M3 PR chain (#20). When the stack squashes, this is the natural last commit.

Em-dash purge (`grep -rn '—'` now returns 0)

Where Count
.rs files 51
Cargo.toml comments 5
.md docs (ADRs, tutorial, SDK + deployment landings) 366

#![cfg_attr(not(test), warn(unused_crate_dependencies))] added to every crate root

  • crates/shepherd-sdk, crates/shepherd-sdk-test
  • modules/{example,twap-monitor,ethflow-watcher}
  • modules/examples/{price-alert,balance-tracker}

Unused-dep cleanup driven by the lint

  • shepherd-sdk dropped serde (only serde_json is imported directly; cowprotocol's serde derive rides through transitively).
  • balance-tracker dropped its direct alloy-primitives dep — now goes via shepherd_sdk::prelude::{Address, U256, address}. Tests adapt.

thiserror conversions

  • shepherd_sdk::host::HostError: was a plain struct; now #[derive(thiserror::Error)] with #[error(\"{domain}: {message} (code={code}, kind={kind:?})\")]. Added thiserror = \"2\" to the crate.
  • modules/twap-monitor::BuildError: hand-rolled impl Display replaced with derive + #[from] cowprotocol::Error. Call site collapses to ?.
  • modules/ethflow-watcher::BuildError: same conversion (4 variants, one #[from]).

Both modules pick up thiserror = \"2\" as a direct dep.

Verification

  • cargo clippy --all-targets --workspace -- -D warnings — clean.
  • cargo test --workspace121 tests pass (nexum-engine 41, shepherd-sdk 27, shepherd-sdk-test 8 + 1 doctest, twap-monitor 13, ethflow-watcher 7, price-alert 11, balance-tracker 13).

Architecture notes (deliberate non-changes)

  • #[non_exhaustive] is not applied to public enums. HostErrorKind / LogLevel mirror the WIT 0.2 enums (locked at the WIT contract layer); RetryAction / PollOutcome are intentional 3- and 5-arm contracts with no expected growth. If a future kind shows up, the rule applies then.
  • parse_config / parse_settings in the example modules return Result<T, String> rather than a typed enum. The rule's "no string-wrapping" applies to error variants that wrap an upstream std::error::Error; one-shot config parsers with bespoke per-field messages are pragmatic. The error surface is internal to the module's init.

Linear: chore (not tied to a specific BLEU issue).

QA pass against the team's rust-idiomatic skill ahead of M4. All
mandatory rules now hold; the cleanup is mostly mechanical with a
handful of small typing improvements where the rule asked for one
thiserror enum per error type.

## Em-dash purge (rule: "no em-dashes anywhere")

Replaced every U+2014 with " - " across .rs / .toml / .md:
  - 51 source-file occurrences
  - 5 Cargo.toml comments
  - 366 occurrences across docs/*.md (most in ADRs and the
    deployment / tutorial / sdk landings)

Grep gate: `grep -rn '—' crates/ modules/ docs/` returns 0.

## `#![cfg_attr(not(test), warn(unused_crate_dependencies))]`

Added to every crate root that previously lacked it:
  - crates/shepherd-sdk/src/lib.rs
  - crates/shepherd-sdk-test/src/lib.rs
  - modules/{example,twap-monitor,ethflow-watcher}/src/lib.rs
  - modules/examples/{price-alert,balance-tracker}/src/lib.rs

`crates/nexum-engine/src/main.rs` already had it.

## Unused-dep cleanup driven by the lint

  - shepherd-sdk dropped `serde` (only `serde_json` is actually
    imported; cowprotocol re-exports carry their own serde derive
    transitively).
  - balance-tracker dropped its direct `alloy-primitives` dep —
    now goes through `shepherd_sdk::prelude::{Address, U256,
    address}`. Tests adapt.

## thiserror conversions (rule: "one flat thiserror enum per
## module/backend; no String-wrapping of upstream errors")

  - `shepherd_sdk::host::HostError` gains `#[derive(thiserror::
    Error)]` + `#[error("{domain}: {message} (code={code},
    kind={kind:?})")]`. Was a plain struct without Display.
    Added `thiserror = "2"` as a dep.
  - `modules/twap-monitor::BuildError`: hand-rolled Display impl
    replaced with `#[derive(thiserror::Error)]` + per-variant
    `#[error(...)]` + `#[from] cowprotocol::Error`. The map_err
    at the call site collapses to `?`.
  - `modules/ethflow-watcher::BuildError`: same conversion (4
    variants, one of them `#[from]`).

Both modules add `thiserror = "2"` as a direct dep.

## Verification

  - `cargo clippy --all-targets --workspace -- -D warnings` clean.
  - `cargo test --workspace`: 121 tests pass.
    - nexum-engine 41, shepherd-sdk 27, shepherd-sdk-test 8 + 1
      doctest, twap-monitor 13, ethflow-watcher 7, price-alert
      11, balance-tracker 13.

## Architecture notes (no code changes)

  - `#[non_exhaustive]` is *not* applied to public enums
    (`HostErrorKind`, `LogLevel`, `RetryAction`, `PollOutcome`).
    The first two mirror the WIT 0.2 enums (locked at the WIT
    contract layer); the last two are intentional 3- and 5-arm
    contracts with no expected growth. If a future kind shows
    up, the rule applies then.
  - `parse_config` / `parse_settings` in the example modules
    return `Result<T, String>` rather than a typed enum. The
    rule's "no string-wrapping" applies to error variants that
    *wrap* an upstream `std::error::Error`; one-shot config
    parsers with bespoke per-field messages are pragmatic. The
    error surface is internal to the module's `init` and not
    part of the orderbook retry contract.
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