bytecodealliance / bytecodealliance/wstd

wstd::main doesn't set exit code on failure

Open
#109 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
133
Forks
19
Avg merge
6d 19h
Merged PRs (30d)
5

Description

When using the `#[wstd::main]` i would expect that an error would set another exitcode than 0.
This beavior is the same right now as tokio::main in a none wasm-application.

Example usage:

```rust
use std::error::Error;
use wstd::http::{Body, Client, Request};

#[wstd::main]
async fn main() -> Result<(), Box> {
let request = Request::get("https://non-existing-url.example.com")
.body(Body::empty())?;

let _response = Client::new().send(request).await?;

Ok(())
}
```

This will return Exit-code 0 when compiled to wasip2 through the wasi-run WIT-interface, and the error form the application will be throwed away between the wit-interface.
Is this the intended behavior?

For example right now i have to do this to make my "main" applications async

```rust
use std::error::Error;
use wstd::http::{Body, Client, Request};

fn main() {
wstd::runtime::block_on(async move {
if let Err(err) = async_main().await {
eprintln!("{err}");
std::process::exit(1);
}
});
}

async fn async_main() -> Result<(), Box> {
let request = Request::get("https://non-existing-url.example.com").body(Body::empty())?;

let _response = Client::new().send(request).await?;

Ok(())
}
```

Contributor guide

Open the contributing guide

Research direction

Start by locating the implementation of #[wstd::main] and tracing how a Result error crosses the wasi-run WIT interface. Compare its behavior with the tokio::main pattern described in the issue. Done means a failing async main returns a nonzero exit code and does not silently discard the error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.