Repository navigation
Forward error causes across the WASM worker boundary (0.10.1) - #17
Merged
Merged
Conversation
The worker protocol serialized only name/code/message/details, so a
NecRuntimeError("<op> failed at the WASM boundary") from a worker-backed
model lost its cause (e.g. "memory access out of bounds", "Aborted()").
serializeError now emits an optional, structured-clone-safe
cause: { name, message }; reviveError and the client's crash path
rebuild it as an Error with the same name and message. Older workers
that omit the field still revive with cause === undefined.
NecStateError accepts an optional cause argument so state errors keep
theirs too.
Bump @necpp-engine/wasm to 0.10.1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PyKgo3fEVyzmSVf2CVaERy
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.
Problem
Worker-backed models (
createNecWorkerModel,createNecArraySolver) wrap a WASM trap asNecRuntimeError("<op> failed at the WASM boundary", { cause }). The worker protocol dropped thatcause:serializeErrorsent only name/code/message/details, andreviveErrorand the client'scrashpath rebuilt errors withdetailsalone. Callers saw "solve failed at the WASM boundary" and never the reason, such as "memory access out of bounds" or "Aborted()".Change
serializeErrornow emits an optionalcause: { name, message }, built from the error'scause. The object is plain strings, so it survives structured clone. A non-Errorcause usesString(cause)as its message. A plainErrorkeeps its owncausetoo.reviveErrorand the worker-clientcrashpath rebuild the cause as anErrorwith the samenameandmessage. Both go through the newreviveErrorOptions.cause === undefined.NecStateErroraccepts an optional fourthcauseargument, so revived state errors keep both their operation/state and their cause.docs/wasm-api.md.Tests
NecRuntimeErrorwrapping a realWebAssembly.RuntimeErrorround-trips throughserializeError,structuredCloneandreviveError. The tests use a tiny module whose exported function runsunreachable. The revived error keepscause.name === "RuntimeError", the original message and its details.cause === undefined.Error. ANecStateErrorkeeps operation/state plus its cause. A plainErrorkeeps its own cause.createNecWorkerModelFromHostover a realMessageChannel, a failure thrown in the worker and acrashmessage both reach the caller with their cause.Locally,
typecheckpasses, as do the worker-protocol and worker-client tests (27/27, 5 repeated runs). The suites that need the Emscripten build couldn't run here because the generated WASM is missing; they fail the same way on unmodified master. CI runs them.Release (not done in this PR)
After merge, pushing tag
wasm-v0.10.1on the merge commit publishes the tested tarball to npm with--provenance. Thereleasejob inbuild.ymlchecks that the tag matchespackage.json. The tag is left for the maintainer.Generated by Claude Code