refactor(sdk): add Fault constructors, reject zero interval - #335
Merged
Conversation
The three example modules each carried a local one-line lifter into Fault::InvalidInput, drifted into two names and two signatures. Replace them with inherent constructors on Fault itself, one per free-text variant, each taking impl Into<String>. RateLimited and Timeout are unit variants and get none. price-alert clamped every_n_blocks = 0 up to 1, silently firing on every block. Reject it instead, matching http-probe, with a test pinning the refusal. Dropping the clamp without the refusal is not an option: is_multiple_of(0) is true only for block 0, so a zero would silently mean "never fire". AI Assistance: Claude Opus 5 used for the constructor rollout, the call site migration and the price-alert refusal test.
The value was clamped silently until this branch made it a boot refusal, so the config comment now has something an operator needs. AI Assistance: Claude Opus 5 used for the change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds inherent constructors on
Faultincrates/nexum-sdk/src/host.rs, one per free-text variant:Fault::unsupported,unavailable,denied,invalid_input,internal, each takingimpl Into<String>.RateLimitedandTimeoutare unit variants and get none. The three module-local lifters are deleted and their call sites moved onto the constructors:balance-tracker'sinvalid_input,http-probe'sinvalid_inputandinternal, andprice-alert'sinvalid. http-probe's inlineFault::InvalidInput(detail)in theFetchErrorarm goes through the constructor too, for consistency; the arm itself is unchanged.price-alertno longer clampsevery_n_blocks = 0up to 1. It now refuses withevery_n_blocks must be >= 1, matching http-probe, and a new test pins the refusal.Why
Closes #140. Every example module reaches the SDK config conversion through
config::get_required(...)?, so the only thing the local helpers still did was lift a free-text detail, and three copies had drifted into two names and two signatures. Per the issue's settled decisions the lifter becomes inherent constructors onFault, where the type lives, discoverable by autocomplete and idiomatic; all five free-text variants get one so the rule is uniform rather than arbitrary.A zero interval is rejected in both throttling modules rather than clamped. It fails loudly at
initwhile the operator is watching, instead of producing a module that looks configured and quietly does the maximum work. Removing the clamp in favour of nothing was never on the table:is_multiple_of(0)is true only for block 0, so an unclamped zero would silently mean "never fire". Blast radius is bounded to the two examplecomponent.tomlfiles, both of which set1.Testing
cargo fmt --all,cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, cleanjust build, thencargo nextest run --workspace --all-features --locked, 858 passed, 0 skipped./scripts/workspace-deps-lint.shandcargo machete, both cleanparse_config_rejects_zero_every_n_blocksin price-alert. http-probe'sparse_config_rejects_missing_urls_and_zero_throttleis untouched.AI Assistance
Claude Opus 5 used for the constructor rollout, the call site migration and the price-alert refusal test.