Skip to content

web-rwkv-wasm: surface the full error chain across the JS boundary#64

Open
sebastian-zm wants to merge 1 commit into
cryscan:mainfrom
sebastian-zm:wasm-surface-error-chain
Open

web-rwkv-wasm: surface the full error chain across the JS boundary#64
sebastian-zm wants to merge 1 commit into
cryscan:mainfrom
sebastian-zm:wasm-surface-error-chain

Conversation

@sebastian-zm

Copy link
Copy Markdown

Quick follow-up to #62 — a small DX fix to the wasm crate I just added there. Sorry for the
immediate second PR on the same code.

Summary

The err() helper that converts Rust errors into JsError formatted them with
Display ({}). For the runtime's top-level error type that Display impl is
just the string "tensor error", so every failure crossing the JS boundary
collapsed to that one useless message — the actual cause (shape mismatch,
missing tensor, etc.) was dropped.

This switches err() to format with {:?}, which preserves the full
anyhow cause chain, and takes impl Into<anyhow::Error> so call sites build
ad-hoc messages with anyhow::anyhow!(...).

Before / after

Loading a model whose tensors don't line up, as seen from JS:

// before
Error: tensor error

// after
Error: tensor error
Caused by:
    tensor shape not match: (96, 2048, 1, 1) vs. (2048, 96, 1, 1)

Same failure, but now it's actually diagnosable without a Rust-side debug build.

Scope

  • One file (crates/web-rwkv-wasm/src/session.rs), no API/behavior change on the
    success path — only the text of the Error thrown to JS.
  • The few call sites that passed a format!(...) string now pass
    anyhow::anyhow!(...) so they satisfy the Into<anyhow::Error> bound.

The session bindings collapsed every failure to its top-level message
(`JsError::new(&err.to_string())`). For inference errors that meant JS only
ever saw `RuntimeError`'s `Display` — the literal string `"tensor error"` —
which hides the inner `TensorError` (e.g. `tensor shape not match: ...`) that
actually explains the failure. Debugging a failing model from the browser was
effectively impossible.

Format errors with `{:?}` so `anyhow::Error`'s full "Caused by:" chain reaches
JS, and route the ad-hoc buffer-length validation messages through
`anyhow::anyhow!` so they keep flowing through the same helper.

No API change; only the text of thrown errors becomes more informative.
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