From 99ad55e578ea169892c8539d923f84f3e019bccf Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Sat, 14 Sep 2024 13:40:40 +0200 Subject: [PATCH] Add function to downcast a stream error to a network-related error. Similar to the existing `filesystem-error-code` and `http-error-code` functions. --- wit/network.wit | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wit/network.wit b/wit/network.wit index 8c13b34..993c4ce 100644 --- a/wit/network.wit +++ b/wit/network.wit @@ -1,5 +1,8 @@ @since(version = 0.2.0) interface network { + @unstable(feature = network-error-code) + use wasi:io/error@0.2.1.{error}; + /// An opaque resource that represents access to (a subset of) the network. /// This enables context-based security for networking. /// There is no need for this to map 1:1 to a physical network interface. @@ -105,6 +108,19 @@ interface network { permanent-resolver-failure, } + /// Attempts to extract a network-related `error-code` from the stream + /// `error` provided. + /// + /// Stream operations which return `stream-error::last-operation-failed` + /// have a payload with more information about the operation that failed. + /// This payload can be passed through to this function to see if there's + /// network-related information about the error to return. + /// + /// Note that this function is fallible because not all stream-related + /// errors are network-related errors. + @unstable(feature = network-error-code) + network-error-code: func(err: borrow) -> option; + @since(version = 0.2.0) enum ip-address-family { /// Similar to `AF_INET` in POSIX.