Skip to content

Commit 7ccd258

Browse files
authored
Use trappable_error_type in WASIp3 sockets (#11373)
This commit updates to using the `trappable_error_type` in bindings generated for WASIp3 to mirror what happens in WASIp2, removing an extra `Result<Result<..>>` layer to only have one layer of results.
1 parent e6a662b commit 7ccd258

7 files changed

Lines changed: 185 additions & 210 deletions

File tree

crates/wasi/src/p2/network.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use core::net::SocketAddr;
2-
31
use crate::p2::bindings::sockets::network::ErrorCode;
42
use crate::sockets::SocketAddrCheck;
53
use crate::{SocketAddrUse, TrappableError};
4+
use core::net::SocketAddr;
65

76
pub type SocketResult<T> = Result<T, SocketError>;
87

crates/wasi/src/p3/bindings.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ mod generated {
9696
"wasi:cli/terminal-output/terminal-output": crate::p3::cli::TerminalOutput,
9797
"wasi:sockets/types/tcp-socket": crate::p3::sockets::tcp::TcpSocket,
9898
"wasi:sockets/types/udp-socket": crate::p3::sockets::udp::UdpSocket,
99-
}
99+
},
100+
trappable_error_type: {
101+
"wasi:sockets/types/error-code" => crate::p3::sockets::SocketError,
102+
},
100103
});
101104
}
102105
pub use self::generated::LinkOptions;

crates/wasi/src/p3/sockets/host/types/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
use crate::p3::bindings::sockets::types::{ErrorCode, Host};
2+
use crate::p3::sockets::{SocketError, WasiSockets};
3+
use crate::sockets::{SocketAddrCheck, SocketAddrUse, WasiSocketsCtxView};
14
use core::net::SocketAddr;
2-
35
use wasmtime::component::Accessor;
46

5-
use crate::p3::bindings::sockets::types::Host;
6-
use crate::p3::sockets::WasiSockets;
7-
use crate::sockets::{SocketAddrCheck, SocketAddrUse, WasiSocketsCtxView};
8-
97
mod tcp;
108
mod udp;
119

12-
impl Host for WasiSocketsCtxView<'_> {}
10+
impl Host for WasiSocketsCtxView<'_> {
11+
fn convert_error_code(&mut self, error: SocketError) -> anyhow::Result<ErrorCode> {
12+
error.downcast()
13+
}
14+
}
1315

1416
fn get_socket_addr_check<T>(store: &Accessor<T, WasiSockets>) -> SocketAddrCheck {
1517
store.with(|mut view| view.get().ctx.socket_addr_check.clone())

0 commit comments

Comments
 (0)