Skip to content

Commit

Permalink
Add function to downcast a stream error to a network-related error. S…
Browse files Browse the repository at this point in the history
…imilar to the existing `filesystem-error-code` and `http-error-code` functions.
  • Loading branch information
badeend committed Sep 14, 2024
1 parent 74ea247 commit 99ad55e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions wit/network.wit
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<error>) -> option<error-code>;

@since(version = 0.2.0)
enum ip-address-family {
/// Similar to `AF_INET` in POSIX.
Expand Down

0 comments on commit 99ad55e

Please sign in to comment.