Skip to content

refactor(sdk): convert bind-macro error/level shims to From impls#358

Closed
lgahdl wants to merge 1 commit into
nullislabs:developfrom
bleu:fix/264-bind-macro-from-impls
Closed

refactor(sdk): convert bind-macro error/level shims to From impls#358
lgahdl wants to merge 1 commit into
nullislabs:developfrom
bleu:fix/264-bind-macro-from-impls

Conversation

@lgahdl

@lgahdl lgahdl commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #264, #286. Follow-up to #185's chain-log WIT boundary cleanup, which converted assemble_log/project_chain_log into From impls under the "verb-named conversions should be From" idiom.

nexum-sdk's bind_host_via_wit_bindgen! still emitted four pure, infallible type-to-type conversions as named functions (convert_chain_err, convert_fault, sdk_fault_into_wit, convert_level — the issue's text names three of these under an older pre-rename naming, convert_err/sdk_err_into_wit; the fourth, convert_chain_err, was added since but is the same shape), so call sites read .map_err(sdk_fault_into_wit) instead of plain ?.

All four become From impls instead. This is orphan-rule-allowed because the macro always expands inside the per-cdylib module crate, where the wit-bindgen-generated type is local and either sits as Self or covers the From<T> type parameter — exactly the mechanism #185 already established.

Also closes #286: that issue asked for exactly From/TryFrom between the wit-bindgen Fault and the SDK Fault — filed against the pre-shim state where call sites converted "by hand" (before convert_fault/sdk_fault_into_wit existed as named functions). The impl From<nexum::host::types::Fault> for $crate::host::Fault and its reverse added here are exactly that conversion, done idiomatically. No separate work needed.

Ripples to:

  • Every module lib.rs call site: twap-monitor, ethflow-watcher, http-probe, stop-loss, price-alert, balance-tracker.map_err(sdk_fault_into_wit)? becomes plain ? (the enclosing fn's Err type already is the wit-local Fault, so ? auto-converts via the new From impl).
  • shepherd-sdk's own bind_cow_host_via_wit_bindgen!, whose convert_cow_err called convert_fault(f) internally — updated to f.into(). (convert_cow_err itself is left as a named function; it's a different file/pattern not named by this issue.)
  • Doc comments across all of the above that named the old functions.

No behavior change — pure ergonomics/idiom, as scoped in the issue.

Test plan

  • cargo build --release --target wasm32-wasip2 for all 12 guest modules — clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • cargo test --workspace --all-features --locked — full suite green, all doctests pass
  • Independent second-pass review (orphan-rule reasoning, dangling call-site check, doc accuracy) — no findings

nexum-sdk's bind_host_via_wit_bindgen! emitted convert_chain_err,
convert_fault, sdk_fault_into_wit, and convert_level as named
functions for pure, infallible type-to-type conversions, so call
sites read .map_err(sdk_fault_into_wit) instead of plain ?. All four
become From impls instead - orphan-rule-allowed because the macro
always expands in the per-cdylib module crate, where the wit-bindgen
type is local and covers the From<T> type parameter. Ripples to
every module lib.rs call site (twap-monitor, ethflow-watcher,
http-probe, stop-loss, price-alert, balance-tracker) and to
shepherd-sdk's own bind_cow_host_via_wit_bindgen!, which called
convert_fault internally. No behavior change.

Fixes nullislabs#264.
@mfw78

mfw78 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded by #452, which lands the same #264 refactor - the From impls for the bind-macro fault/level shims, in the same two files (crates/nexum-sdk/src/wit_bindgen_macro.rs, crates/shepherd-sdk/src/wit_bindgen_macro.rs) plus the same module call sites - on the M3 Videre train.

#358 predates the train and targets develop directly; per review (#452), keeping one avoids the duplicate work and a merge conflict once either lands. #264 will close when #452 lands.

Reopen if landing this directly on develop (ahead of the train) is preferred.

@mfw78 mfw78 closed this Jul 21, 2026
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.

sdk: From/TryFrom between the wit-bindgen Fault and the SDK Fault sdk: convert the bind-macro error/level shims to From impls

2 participants