Skip to content

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

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

eduardomourar wants to merge 3 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
Contributor

Merging this PR will improve performance by 55.94%

2 warnings, 1 note

⚠️ 121 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

⚠️ 12 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes 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

⚡ 13 improved benchmarks
✅ 392 untouched benchmarks
🆕 8 new benchmarks
⏩ 70 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Memory factor_small_factors_and_a_large_prime 104.8 KB 15.4 KB ×6.8
⚡ CPU Simulation split_lines 14.4 ms 4.3 ms ×3.3
⚡ CPU Simulation split_numeric_suffix 14.6 ms 4.5 ms ×3.2
⚡ CPU Simulation factor_small_factors_and_a_large_prime 1,012.7 µs 682.1 µs +48.46%
⚡ CPU Simulation join_partial_overlap 18.7 ms 15.1 ms +23.41%
⚡ CPU Simulation join_full_match 21.8 ms 18.3 ms +19.18%
⚡ CPU Simulation join_french_locale 21.8 ms 18.3 ms +19.14%
⚡ CPU Simulation join_unicode_locale 2.2 ms 1.8 ms +19.08%
⚡ CPU Simulation join_custom_separator 22.1 ms 18.8 ms +17.82%
⚡ CPU Simulation unexpand_large_file[10] 88.5 ms 83.4 ms +6.14%
⚡ CPU Simulation unexpand_many_lines[100000] 42.6 ms 40.2 ms +6.08%
⚡ CPU Simulation split_number_chunks_round_robin 30.3 ms 28.9 ms +4.87%
⚡ CPU Simulation split_bytes 781.9 µs 756.1 µs +3.42%
🆕 Memory factor_batch_of_largest_u64s N/A 796 KB N/A
🆕 Memory factor_batch_of_semiprimes N/A 199.5 KB N/A
🆕 Memory factor_batch_of_small_numbers N/A 7.5 MB N/A
🆕 Memory factor_batch_of_smallest_u128s N/A 885.4 KB N/A
🆕 CPU Simulation factor_batch_of_largest_u64s N/A 557.4 ms N/A
🆕 CPU Simulation factor_batch_of_semiprimes N/A 794.2 ms N/A
🆕 CPU Simulation factor_batch_of_small_numbers N/A 138.6 ms N/A
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

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 (2038686) with main (fca3de1)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 (8406d69) during the generation of this report, so fca3de1 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

I have put this one back to draft. It had too many files that were changed so I created the following spinoff PRs that need to be merged first:

WASI reports directory errors with different errno values than Unix.
Add `wasi_normalize_open_error` and `wasi_normalize_read_error` to map
them to `ErrorKind::IsADirectory`. The functions do nothing on other
targets.

On WASI preview 2, `stat` on a symlink reports the inode of the link.
`FileInformation::from_path` now opens a dereferenced symlink and uses
`fstat`, so two paths to the same file compare as equal.
Use the new `uucore::error` helpers in cat, factor, sort, split, tee,
tr and wc. These utilities now report `IsADirectory` on WASI instead
of a raw errno. cat also maps the wasi-libc `ELOOP` value.

On WASI preview 2, a nonzero `ExitCode` returned from main becomes 1.
The multicall binary now passes the utility exit code to `exit` on
preview 2.
Add integration tests for the WASI behavior. Annotate tests that the
WASI sandbox cannot run with `#[uutests::wasi_ignore(ReasonKey)]`.
Add `#[uutests::wasip2_ignore(ReasonKey)]` for limitations specific to
wasm32-wasip2. Exclude tests that apply a file descriptor limit to the
wasmtime runner with `#[cfg(not(wasi_runner))]`.

Run the wasip2 integration suite in `wasi.yml`. Document the new
macro in `docs/src/wasi-test-gaps.md`.

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