Skip to content

feat(sdk): mark HostErrorKind + LogLevel #[non_exhaustive] (COW-1029)#35

Open
brunota20 wants to merge 1 commit into
fix/supervisor-alive-on-init-errfrom
feat/non-exhaustive-sdk-enums-cow-1029
Open

feat(sdk): mark HostErrorKind + LogLevel #[non_exhaustive] (COW-1029)#35
brunota20 wants to merge 1 commit into
fix/supervisor-alive-on-init-errfrom
feat/non-exhaustive-sdk-enums-cow-1029

Conversation

@brunota20

Copy link
Copy Markdown
Collaborator

What does this PR do?

Applies forward-compatibility hardening to the two SDK enums that mirror the WIT type system. Both `HostErrorKind` (7 variants) and `LogLevel` (5 variants) now carry `#[non_exhaustive]`. Once WIT adds a new variant (e.g. a future `WasmTrap` / `Critical`), the SDK side mirrors it without breaking downstream `match` sites.

First M4 production-hardening issue landed.

Why

The COW-1029 issue body originally proposed waiting until WIT actually grew before applying `#[non_exhaustive]`. Re-scoped for M4 production hardening: stable API contracts before mainnet matter more than the 10 wildcard arms the change costs.

Changes

  • `crates/shepherd-sdk/src/host.rs`: `#[non_exhaustive]` on `LogLevel` + `HostErrorKind`; rustdoc cites the policy + wildcard-arm guidance.
  • `modules/{twap-monitor,ethflow-watcher,examples/price-alert,examples/stop-loss}/src/lib.rs`: wildcard arms in `sdk_err_into_wit` (-> `HostErrorKind::Internal`) and `convert_level` (-> `logging::Level::Info`).
  • `docs/adr/0009-host-trait-surface.md`: Consequences section updated to reflect the M4 application of `#[non_exhaustive]`.

balance-tracker is unaffected (still on the M2-era direct-wit-bindgen pattern; not refactored to Host trait). Tracked as the optional follow-up from the COW-1063 QA matrix.

Out of scope

  • `RetryAction` + `PollOutcome` stay exhaustive. They are domain-locked to `OrderPostErrorKind::is_retriable` (cowprotocol) and the `IConditionalOrder` Solidity interface respectively; the issue body explicitly exempts them.
  • `HostError` struct stays without `#[non_exhaustive]`. Adding it would break the 5 modules that construct `HostError { ... }` inline. Worth a follow-up if/when the WIT struct grows a field.

Breaking changes

For downstream module authors: `match` on SDK `HostErrorKind` or `LogLevel` now requires a wildcard arm. The 4 production modules updated here are the only known consumers; outside that we're pre-publish so the impact window is zero.

Testing

  • `cargo test --workspace` -> 151 host tests + 6 doctests passing.
  • `cargo clippy --all-targets --workspace -- -D warnings` clean.
  • `cargo fmt --all --check` clean.
  • All 5 wasm modules build under `wasm32-wasip2 --release`.
  • 0 em-dashes in changed files.

AI assistance disclosure

AI Assistance: this change + description was produced by a Claude Code agent (Claude Opus 4.7 1M context). A human (Bruno) reviewed and is accountable for the result.

Linear: COW-1029. First M4 issue landed; stacks on #34 (supervisor alive fix).

Applies forward-compatibility hardening to the two SDK enums that
mirror the WIT type system. Both `HostErrorKind` (7 variants) and
`LogLevel` (5 variants) now carry `#[non_exhaustive]`. The WIT
contract drives the variant set: once a new variant is added in WIT
(e.g. a future `WasmTrap` HostErrorKind, or a `Critical` LogLevel),
the SDK side mirrors it without breaking downstream `match` sites.

`RetryAction` (3 variants) and `PollOutcome` (5 variants) stay
exhaustive - they're domain-locked to the cowprotocol
`OrderPostErrorKind::is_retriable()` contract and the
`IConditionalOrder` Solidity interface respectively. The
`#[non_exhaustive]` issue body (COW-1029 / BLEU-853) explicitly
exempts them.

## Match-site updates

The 4 modules that ported to the M3 Host trait pattern (price-alert,
stop-loss, twap-monitor, ethflow-watcher) match on SDK `HostErrorKind`
and `LogLevel` in their `sdk_err_into_wit` and `convert_level`
adapters. Each gains a wildcard arm:

  _ => HostErrorKind::Internal  // safest catch-all
  _ => logging::Level::Info     // most neutral default

balance-tracker is unaffected (it predates the host-trait refactor
and matches against wit-bindgen types directly, not SDK types). The
balance-tracker port is tracked as the COW-1063 QA matrix optional
follow-up.

## Considered alternatives

Issue body originally proposed "open as tracking ticket; trigger
when WIT adds the 8th HostErrorKind". Rejected for M4: production
hardening means stable API contracts BEFORE shipping. Applying
non_exhaustive proactively trades 10 wildcard arms (5 modules x 2
match blocks, minus 1 module that doesn't have the adapter) for
forward-compat stability.

## Doc + ADR updates

- `crates/shepherd-sdk/src/host.rs`: rustdoc on each enum cites the
  COW-1029 decision + wildcard-arm guidance for module adapters.
- `docs/adr/0009-host-trait-surface.md`: Consequences section
  updated. The "ADR-0009 follow-up COW-1029" stub is replaced with
  the applied state.

## Validation

- `cargo test --workspace` -> 151 host tests + 6 doctests passing
  (no change in count).
- `cargo clippy --all-targets --workspace -- -D warnings` clean.
- `cargo fmt --all --check` clean.
- 5 wasm modules build under `wasm32-wasip2 --release`.
- 0 em-dashes in changed files.

Linear: COW-1029. First M4 issue landed.
@linear-code

linear-code Bot commented Jun 18, 2026

Copy link
Copy Markdown

COW-1029

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