Skip to content

cmd/wazero: exit non-zero on an invalid -listen or -mount - #2537

Merged
ncruces merged 2 commits into
wazero:mainfrom
NotAFlightRisk:fix-cli-invalid-flag-exit-code
Aug 29, 2026
Merged

ncruces merged 2 commits into
wazero:mainfrom
NotAFlightRisk:fix-cli-invalid-flag-exit-code

Conversation

@NotAFlightRisk

Copy link
Copy Markdown
Contributor

cmd/wazero/wazero_test.go doesn't contain the word listen anywhere, and the one invalid mount row in TestRun_Errors has // not found sat next to it. Which is proably why nobody's noticed that three of the four cases below print an error and then run the module regardless.

Each row is wazero run <flags> cmd/wazero/testdata/wasi_arg.wasm, from the repo root:

flags stderr exit
-mount=/nope/nope invalid mount: path "/nope/nope" error: stat ... 1
-mount=cmd/wazero/testdata/fs/bear.txt invalid mount: path "..." is not a directory 0
-listen 8080 invalid listen 0
-listen localhost:abc invalid listen port: strconv.Atoi: parsing "abc": invalid syntax 0

Only the top one's right. The other three start the guest with no mount and no listener and still hand back 0, so a CI job wrapping wazero passes on a server that never listened.

The listen side is worse than it looks: validateListens never assigns the named rc it returns, so the rc != 0 branch in its caller has never fired.

Three lines of fix against twelve of test, which is a daft ratio - they're three more rows in the existing TestRun_Errors table though, rather than a new harness.

The mount change is the bit with any chance of biting someone. If you'd been pointing -mount at a file and getting away with it, thats exit 1 now instead of a DirFS over a regular file. Nothing in the repo does that as far as I can see, I havent looked outside it.

validateListens returned the zero-valued named return from both of its
failure branches, so the caller's `rc != 0` check never fired. The
`!stat.IsDir()` branch of validateMounts printed its message and fell
through with no return at all, mounting the file as a DirFS.

In both cases `wazero run` printed the error, ran the module anyway and
exited 0.

Signed-off-by: Iain <[email protected]>
@NotAFlightRisk
NotAFlightRisk requested a review from a team as a code owner August 29, 2026 00:09
@ncruces

ncruces commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Seems reasonable. Can you fix the test?

@NotAFlightRisk

Copy link
Copy Markdown
Contributor Author

Cheers @ncruces, pushed. Only the mount row was broken - passing a bare file path meant Windows split on the drive-letter colon, so it stat'd C and never got as far as the is not a directory branch. Given it a guest path like the other mount tests have. I'd only run it on Linux, wher there's no colon to trip over.

@ncruces
ncruces merged commit f477955 into wazero:main Aug 29, 2026
43 checks passed
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