Skip to content

fix(js): return WasmerError from sync filesystem calls - #554

Open
owen-harborcoat wants to merge 1 commit into
wasmerio:mainfrom
owen-harborcoat:fix/fs-sync-errors
Open

owen-harborcoat wants to merge 1 commit into
wasmerio:mainfrom
owen-harborcoat:fix/fs-sync-errors

Conversation

@owen-harborcoat

Copy link
Copy Markdown

SandboxFileSystem.stat, readDir, mkdir and remove call methods that are synchronous in the core, so rethrow(this.#core.stat(path)) throws before rethrow gets to catch anything. Callers get a plain Error with name: "WasmerError" and a code, and WasmerError.is() returns false for it. readFile, writeFile and rename are async in the core and were fine.

await sandbox.fs.stat("/workspace/missing.txt").catch((e) => WasmerError.is(e)); // false
await sandbox.fs.readFile("/workspace/missing.txt").catch((e) => WasmerError.is(e)); // true

Switched the four to rethrowSync, and added a check after the existing fs round trip in runtime.test.mjs.

I couldn't build the wasm locally, so I tested by applying the same change to the published 0.19.1 dist/index.js. The new assertions fail 4/4 without it and pass with it. Seen on 0.18.0, 0.19.0 and 0.19.1, Node 24 on Windows and Node 22/24 on Linux CI.

🤖 Generated with Claude Code

stat, readDir, mkdir and remove are synchronous in the core, so
rethrow(this.#core.x(...)) evaluated the throwing call before rethrow could
catch it. They rejected with a plain Error named WasmerError, which
WasmerError.is() does not recognise. Use rethrowSync for them.

This branch has not been deployed

No deployments
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