Skip to content

[WasmFS] Ensure error codes are negative in the Node backend#26598

Merged
sbc100 merged 1 commit intoemscripten-core:mainfrom
kleisauke:wasmfs-ensure-negative-error-codes
Apr 2, 2026
Merged

[WasmFS] Ensure error codes are negative in the Node backend#26598
sbc100 merged 1 commit intoemscripten-core:mainfrom
kleisauke:wasmfs-ensure-negative-error-codes

Conversation

@kleisauke
Copy link
Copy Markdown
Collaborator

See commit 48459c6 for details.

Split out from #24733, this fixes a test failure in core0.test_fs_js_api_wasmfs_rawfs from that PR.

Copy link
Copy Markdown
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no tests failing because of this bug?

@kleisauke
Copy link
Copy Markdown
Collaborator Author

Why no tests failing because of this bug?

Good question, I suspect it's because absolute path access doesn't work with -sWASMFS -sNODERAWFS (so this code is never reached in that test), but I'll dig into this later.

@kleisauke
Copy link
Copy Markdown
Collaborator Author

For reference, see the CircleCI log at https://circleci.com/gh/emscripten-core/emscripten/1164699 for the failure.

Details
======================================================================
FAIL [0.001s]: test_fs_js_api_wasmfs_rawfs (test_core.core0)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/project/test/common.py", line 377, in resulting_test
    return func(self, *args)
  File "/root/project/test/decorators.py", line 324, in metafunc
    return func(self, *args, **kwargs)
  File "/root/project/test/test_core.py", line 5915, in test_fs_js_api
    self.do_runf('fs/test_fs_js_api.c', 'success')
  File "/root/project/test/common.py", line 1408, in do_runf
    return self._build_and_run(filename, expected_output, **kwargs)
  File "/root/project/test/common.py", line 1456, in _build_and_run
    js_output = self.run_js(js_file, engine, args,
  File "/root/project/test/common.py", line 1040, in run_js
    self.fail('JS subprocess failed (%s): %s (expected=%s).  Output:\n%s' % (error.cmd, error.returncode, assert_returncode, ret))
AssertionError: JS subprocess failed (/root/emsdk/node/22.16.0_64bit/bin/node --stack-trace-limit=50 --trace-uncaught /tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js): 1 (expected=0).  Output:
Aborted(Assertion failed: err < 0, at: /emsdk/emscripten/system/lib/wasmfs/syscalls.cpp,1067,__syscall_renameat)
Aborted(Assertion failed)
/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:552
  var e = new WebAssembly.RuntimeError(what);
          ^

RuntimeError: Aborted(Assertion failed)
    at abort (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:552:11)
    at assert (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:269:5)
    at test_fs_rename (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:2763:456)
    at wasm://wasm/000901ea:wasm-function[49]:0x152b
    at wasm://wasm/000901ea:wasm-function[50]:0x1562
    at /tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:567:12
    at callMain (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:3044:15)
    at doRun (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:3097:24)
    at run (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:3110:5)
    at removeRunDependency (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:798:11)
    at receiveInstance (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:671:5)
    at receiveInstantiationResult (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:688:12)
    at createWasm (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:714:17)
Thrown at:
    at abort (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:552:11)
    at assert (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:269:5)
    at test_fs_rename (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:2763:456)
    at $func49 (wasm://wasm/000901ea:1:5420)
    at $main (wasm://wasm/000901ea:1:5475)
    at /tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:567:12
    at callMain (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:3044:15)
    at doRun (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:3097:24)
    at run (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:3110:5)
    at removeRunDependency (/tmp/emtest_7ktg8cnu/emscripten_test_core0_v8vtv858/test_fs_js_api.js:798:11)


Node.js v22.16.0


----------------------------------------------------------------------
Ran 1145 tests in 674.466s

FAILED (failures=1, skipped=67)

Which is this assert():

assert(err < 0);


auto childPath = getChildPath(name);
return _wasmfs_node_rename(fromPath.c_str(), childPath.c_str());
return -_wasmfs_node_rename(fromPath.c_str(), childPath.c_str());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think this is wrong. IIUC, there are 3 classes of functions at play:

  1. The _wasmfs_node_xxx API. These return positive error codes.
  2. The internal C++ API for wasm (e.g. insertMove). These also return positive error codes.
  3. The __syscall_xxx API: These return negative error codes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about point (2)? See for example:

// Move the file represented by `file` from its current directory to this
// directory with the new `name`, possibly overwriting another file that
// already exists with that name. The old directory may be the same as this
// directory. On success return 0 and otherwise return a negative error code
// without changing any underlying state. This should only be called from
// renameat with the locks on the old and new parents already held.
[[nodiscard]] int insertMove(const std::string& name,
std::shared_ptr<File> file);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh.. I stand corrected. Sorry about that.

@sbc100
Copy link
Copy Markdown
Collaborator

sbc100 commented Apr 2, 2026

lgtm!

@sbc100 sbc100 merged commit 34f6bcf into emscripten-core:main Apr 2, 2026
38 checks passed
@kleisauke kleisauke deleted the wasmfs-ensure-negative-error-codes branch April 2, 2026 17:22
kleisauke added a commit to kleisauke/emscripten that referenced this pull request Apr 3, 2026
kleisauke added a commit that referenced this pull request Apr 4, 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.

2 participants