Skip to content

feat(wasi): normalize wasi error codes - #13625

Draft
eduardomourar wants to merge 5 commits into
uutils:mainfrom
eduardomourar:feat/wasi-error-handling
Draft

eduardomourar wants to merge 5 commits into
uutils:mainfrom
eduardomourar:feat/wasi-error-handling

Conversation

@eduardomourar

@eduardomourar eduardomourar commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Continuation of #12653. Aligns error handling on wasm32-wasip1/wasm32-wasip2 with native Unix behavior, and enables the wasip2 integration test suite.

  • Adds wasi_normalize_open_error/wasi_normalize_read_error/wasi_is_broken_pipe helpers to uucore::error and applies them across cat, rm, wc, csplit, tee, sort, seq, tr, tsort, split, and yes, so directory/broken-pipe errors surface the same ErrorKind and message as on Unix instead of WASI's raw, differently-numbered errnos.
  • Reworks uucore::fs::FileInformation to use real inode/device stat via rustix on WASI instead of a size/type heuristic.
  • Fixes WASI-specific gaps in cp (symlinks, attribute preservation), touch (timestamps), date (clock resolution, set-date), and sort (single-threaded ordering check, since WASI has no threads).
  • Adds/retargets integration tests across most utilities to cover the above, tags WASI-incompatible tests with #[cfg_attr(wasi_runner/wasip2_runner, ignore = "...")], and enables the wasip2 integration run in CI (previously wasip1-only).

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/id/setgid is no longer failing!

@oech3

oech3 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Can we avoid introducing many code with match and cfg, and introduce a fn like process_wasi_err(e)?

@codspeed

codspeed Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 7.8%

2 warnings, 1 note

⚠️ 118 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 1 improved benchmark
✅ 400 untouched benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation sort_long_line[10000] 1,077.8 µs 999.8 µs +7.8%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing eduardomourar:feat/wasi-error-handling (aa5fe0c) with main (49b602c)2

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (cac8be1) during the generation of this report, so 49b602c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@eduardomourar
eduardomourar force-pushed the feat/wasi-error-handling branch from ecc7c96 to 650e875 Compare July 30, 2026 18:09
@eduardomourar eduardomourar changed the title feat(wasi): convert wasi to posix error codes feat(wasi): normalize wasi error codes and exit-code propagation Jul 30, 2026
@eduardomourar

Copy link
Copy Markdown
Contributor Author

Can we avoid introducing many code with match and cfg, and introduce a fn like process_wasi_err(e)?

I had to create 3 separate functions to deal with normalizing the WASI errors, but I think it does what you asked.

@eduardomourar
eduardomourar force-pushed the feat/wasi-error-handling branch 4 times, most recently from 9752428 to d311b90 Compare August 1, 2026 01:22
@eduardomourar
eduardomourar marked this pull request as draft August 1, 2026 08:59
@eduardomourar

eduardomourar commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor Author

WASI reports directory errors and broken pipes with different errno
values than Unix. Add `wasi_normalize_open_error`,
`wasi_normalize_read_error` and `wasi_is_broken_pipe` to map them to
the Unix `ErrorKind`. The functions do nothing on other targets.
Use the new `uucore::error` helpers in cat, dd, rm, wc, tee, sort,
seq, tr, tsort and split. These utilities now report `IsADirectory`
on WASI instead of a raw errno. seq also detects the preview 2 broken
pipe.

Add WASI fallbacks for APIs that WASI does not provide: the `dd`
progress reporter and alarm without threads, `OwnedFileDescriptorOrHandle`
without descriptor duplication, and directory checks in rm and tsort.
Add integration tests for the WASI behavior. Ignore the tests that the
WASI sandbox cannot run and give each a reason.

Build relative symlink targets in the test harness on WASI. Add the
`UUTESTS_WASM_RUNNER_ARGS` variable.

Run the wasip2 integration suite in `wasi.yml` and extend the utility
list. Document the ignore reasons in `docs/src/wasi-test-gaps.md`.
Use nightly for wasm32-wasip2. Only nightly keeps the exit code in
`std::process::exit`.
Remove the directory error normalization from cat, dd and rm. Remove
`wasi_is_broken_pipe`, because seq now gets `BrokenPipe` on preview 2.
tee, tr and wc keep their mappings, because their tests still fail
without them.

Revert the WASI `OwnedFileDescriptorOrHandle::from` in uucore. dd now
takes ownership of the stdout descriptor itself, because WASI cannot
duplicate descriptors. Fix the `USimpleError` import for WASI in dd and
two clippy warnings.
@eduardomourar
eduardomourar force-pushed the feat/wasi-error-handling branch from 0d592ff to aa5fe0c Compare November 1, 2026 00:54

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.

2 participants