Wave icon indicating copy to clipboard operation
Wave copied to clipboard

Use WASI errno values for locally generated provider errors

Open LunaStev opened this issue 1 month ago • 0 comments

Current master follow-up (2026-11-12)

This update records the remaining behavior on the audited master. The historical report and earlier delivered work are retained below; current code paths are Rust rather than the retired Python helpers.

Problem

Provider corrections did not cover every high-level wrapper. Locally rejected invalid arguments still return POSIX -22 under WASI, whose INVAL is -28.

Reproduction and evidence

Audited canonical master 69a67c6e0fb700f37ee6114f5a66d37ee13771a5 (0.0.1-alpha-dev). Matching checkout-built compiler/std were used for compiler probes on Linux amd64 with Rust 1.89.0 and LLVM 21.1.8. Artifact inspection, mocked/projection checks and foreign-target object emission are identified below and are not native execution on those operating systems.

import("std::time::clock")::{time_now_monotonic_duration};import("std::random::fill")::{random_fill,RandomFillResult};import("std::sys::errors")::{SYS_ERR_INVAL};fun main()->i32{var result:RandomFillResult=random_fill(null,-1);println("clock={} random={} expected={}",time_now_monotonic_duration(null),result.error,SYS_ERR_INVAL);return 0;}
target/debug/wavec --std-root "$PWD/std" build repro.wave --target wasm32-wasip1 -O0 --run --out-dir out-O0
target/debug/wavec --std-root "$PWD/std" build repro.wave --target wasm32-wasip1 -O2 --run --out-dir out-O2

Both actual WASI executions print clock=-22 random=-22 expected=-28. These are local argument checks; no host-error injection is needed.

Scope

Use established selected-target errno constants in the remaining wrapper-local validation paths. Preserve native provider errors and the existing zero-length behavior.

Starting points: std/time/clock.wave:38, std/random/fill.wave:26.

Completion criteria

  • [ ] Invalid null/negative cases return target-correct errors.
  • [ ] Zero-length randomness and valid calls keep their contracts.
  • [ ] WASI and native controls exercise wrapper and provider boundaries separately.

This is a bounded newcomer task with the starting point and focused negative/positive checks above.

Related: #1005. Related broad trackers or completed implementations are context, not claims that their entire scope is unfinished.

Original report (historical)

Problem

The WASI providers return raw negative WASI errno values from host imports, but several local validation and overflow paths still synthesize POSIX values. The same invalid-argument condition can therefore produce -22 or -28 depending on which wrapper detects it.

This is observable error misclassification: in WASI Preview 1, 22 means FBIG, 28 means INVAL, 61 means OVERFLOW, and 75 means XDEV. The official WASI header defines those values. Wave already declares WASI SYS_ERR_INVAL=-28 and SYS_ERR_OVERFLOW=-61 in std/sys/errors.wave.

Starting points are filesystem local checks, clock validation, and environment validation. Filesystem range checks also return POSIX -75 instead of WASI -61; unavailable filesystem/process operations use -38, which identifies NETDOWN in WASI rather than NOSYS (52).

Reproduction

Executed at d59bdab376bdc04edacdc8029b256cb8d55b5adf, using the checkout-built compiler and matching std, Rust 1.89.0, LLVM 21.1.8, Node.js 22.22.1 on Linux amd64. Both O0 and O2 produce the following result for wasm32-WASI. These paths reject locally, so no synthetic host-error injection is required.

import("std::sys::wasm::fs")::{close, fsync, lseek, ftruncate};
import("std::sys::wasm::time")::{clock_gettime, TimeSpec};
import("std::sys::wasm::env")::{env_read};
import("std::sys::wasm::io")::{wasi_read};
import("std::time::sleep")::{time_sleep_ns};
fun main() -> i32 {
    var ts: TimeSpec;
    println("close={} sync={} seek={} truncate={}", close(4294967296), fsync(4294967296), lseek(0, 0, 3), ftruncate(0, -1));
    println("clock={} env={} read={} sleep={}", clock_gettime(-1, &ts), env_read(null, 0), wasi_read(-1, null, 0), time_sleep_ns(-1));
    return 0;
}
target/debug/wavec build repro.wave --std-root="$PWD/std" --target=wasm32-wasip1 --out-dir=/tmp/wave-wasi-errors --run -O0
close=-22 sync=-22 seek=-22 truncate=-22
clock=-22 env=-22 read=-28 sleep=-28

An additional controlled-host probe exercised fstat with a successful fd_filestat_get result containing size 9223372036854775808: Wave returned -75 instead of an overflow-domain error. A separate host fd_close failure with errno 28 passed through as -28; unavailable chdir returned -38. Both O0 and O2 produced range=-75, host=-28, unsupported=-38. The oversized stat is a controlled representation-boundary test, not a claim about ordinary file sizes.

Scope

Use the provider's established WASI errno namespace for locally generated argument, range, and unsupported-operation failures. Preserve genuine host errno results and keep portable std-specific contract errors in their separate range.

Related: #754 fixed interruption retry classification. #756 fixed access-mode semantics. #938 owns environment source-capacity growth; this issue does not duplicate that feature. Do not split this numeric-domain mismatch into a separate issue for each wrapper.

Completion criteria

  • [ ] Local validation errors use the intended WASI errno, including existing invalid-argument and overflow constants.
  • [ ] Unsupported operations report an unsupported-function errno rather than a POSIX number that names a different WASI error.
  • [ ] Cover invalid arguments without calling the host and representability overflow with a controlled host result.
  • [ ] Genuine host errors are returned unchanged; interruption retry and existing success behavior stay covered.

LunaStev avatar Oct 18 '26 12:10 LunaStev