From 60c4d3183a5edd046662c7fab72c67ad4a293bdb Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 17 Jan 2025 11:59:02 +0100 Subject: [PATCH] feat(0.3): rework stream error handling Signed-off-by: Roman Volosatovs --- wit-0.3.0-draft/types.wit | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/wit-0.3.0-draft/types.wit b/wit-0.3.0-draft/types.wit index f2ed3a5..36ffcc5 100644 --- a/wit-0.3.0-draft/types.wit +++ b/wit-0.3.0-draft/types.wit @@ -2,7 +2,6 @@ /// Requests and Responses, as well as their headers, trailers, and bodies. interface types { use wasi:clocks/monotonic-clock@0.2.3.{duration}; - use wasi:io/error@0.2.3.{error}; /// This type corresponds to HTTP standard Methods. variant method { @@ -92,18 +91,6 @@ interface types { field-size: option } - /// Attempts to extract a http-related `error-code` from the stream `error` - /// provided. - /// - /// Stream operations may fail with a stream `error` with more information - /// about the operation that failed. This `error` can be passed to this - /// function to see if there's http-related information about the error to - /// return. - /// - /// Note that this function is fallible because not all stream errors are - /// http-related errors. - http-error-code: func(err: borrow) -> option; - /// This type enumerates the different kinds of errors that may occur when /// setting or appending to a `fields` resource. variant header-error { @@ -254,16 +241,24 @@ interface types { resource body { /// Construct a new `body` with the specified stream and trailers. - constructor( + /// This function returns a future, which will resolve + /// to an error code if transmitting stream data or trailers fails. + /// The returned future resolves to success once body stream and trailers + /// are fully transmitted. + new: static func( %stream: stream, trailers: option> - ); + ) -> tuple>>; /// Returns the contents of the body, as a stream of bytes. /// /// This function may be called multiple times as long as any `stream`s /// returned by previous calls have been dropped first. - %stream: func() -> result>; + /// + /// On success, this function returns a stream and a future, which will resolve + /// to an error code if receiving data from stream fails. + /// The returned future resolves to success if body is closed. + %stream: func() -> result>, future>>; /// Takes ownership of `body`, and returns a `trailers`. This function will /// trap if a `stream` child is still alive.