From a39776e6fa21c96fb33b52bdeb89d2c8b8f4cca7 Mon Sep 17 00:00:00 2001
From: Pat Hickey
Date: Fri, 10 Nov 2023 14:32:05 -0800
Subject: [PATCH] move error resource to its own interface. (#56)
* Move error resource to its own interface
Two reasons for this design change:
it is confusing having one type named stream/stream-error and another named stream/error.
this error resource seems useful outside of just streams.
Therefore, we are moving it to a separate interface error in the same package. There are no functional changes to this type.
The doc comments are now more general.
* generate markdown
---
imports.md | 46 ++++++++++++++++++++++++++++------------------
wit/error.wit | 34 ++++++++++++++++++++++++++++++++++
wit/streams.wit | 21 +--------------------
3 files changed, 63 insertions(+), 38 deletions(-)
create mode 100644 wit/error.wit
diff --git a/imports.md b/imports.md
index e08b326..dbca06e 100644
--- a/imports.md
+++ b/imports.md
@@ -2,11 +2,33 @@
+
+
+Types
+
+
+Functions
+
+Returns a string that is suitable to assist humans in debugging
+this error.
+WARNING: The returned string should not be consumed mechanically!
+It may change across platforms, hosts, or other implementation
+details. Parsing this string is a major platform-compatibility
+hazard.
+Params
+
+Return values
+
A poll API intended to let users wait for I/O events on multiple handles
at once.
@@ -64,11 +86,13 @@ stream types.
when it does, they are expected to subsume this API.
Types
-
-pollable
+
+error
+
+#### `type pollable`
+[`pollable`](#pollable)
-#### `resource error`
-
+#### `variant stream-error`
An error for input-stream and output-stream operations.
Variant Cases
@@ -88,20 +112,6 @@ future operations.
Functions
-
-Returns a string that's suitable to assist humans in debugging this
-error.
-The returned string will change across platforms and hosts which
-means that parsing it, for example, would be a
-platform-compatibility hazard.
-Params
-
-Return values
-
Perform a non-blocking read from the stream.
This function returns a list of bytes containing the read data,
diff --git a/wit/error.wit b/wit/error.wit
new file mode 100644
index 0000000..66519ef
--- /dev/null
+++ b/wit/error.wit
@@ -0,0 +1,34 @@
+package wasi:io;
+
+
+interface error {
+ /// A resource which represents some error information.
+ ///
+ /// The only method provided by this resource is `to-debug-string`,
+ /// which provides some human-readable information about the error.
+ ///
+ /// In the `wasi:io` package, this resource is returned through the
+ /// `wasi:io/streams/stream-error` type.
+ ///
+ /// To provide more specific error information, other interfaces may
+ /// provide functions to further "downcast" this error into more specific
+ /// error information. For example, `error`s returned in streams derived
+ /// from filesystem types to be described using the filesystem's own
+ /// error-code type, using the function
+ /// `wasi:filesystem/types/filesystem-error-code`, which takes a parameter
+ /// `borrow` and returns
+ /// `option`.
+ ///
+ /// The set of functions which can "downcast" an `error` into a more
+ /// concrete type is open.
+ resource error {
+ /// Returns a string that is suitable to assist humans in debugging
+ /// this error.
+ ///
+ /// WARNING: The returned string should not be consumed mechanically!
+ /// It may change across platforms, hosts, or other implementation
+ /// details. Parsing this string is a major platform-compatibility
+ /// hazard.
+ to-debug-string: func() -> string;
+ }
+}
diff --git a/wit/streams.wit b/wit/streams.wit
index 8999b28..643d7b7 100644
--- a/wit/streams.wit
+++ b/wit/streams.wit
@@ -6,6 +6,7 @@ package wasi:io;
/// In the future, the component model is expected to add built-in stream types;
/// when it does, they are expected to subsume this API.
interface streams {
+ use error.{error};
use poll.{pollable};
/// An error for input-stream and output-stream operations.
@@ -20,26 +21,6 @@ interface streams {
closed
}
- /// Contextual error information about the last failure that happened on
- /// a read, write, or flush from an `input-stream` or `output-stream`.
- ///
- /// This type is returned through the `stream-error` type whenever an
- /// operation on a stream directly fails or an error is discovered
- /// after-the-fact, for example when a write's failure shows up through a
- /// later `flush` or `check-write`.
- ///
- /// Interfaces such as `wasi:filesystem/types` provide functionality to
- /// further "downcast" this error into interface-specific error information.
- resource error {
- /// Returns a string that's suitable to assist humans in debugging this
- /// error.
- ///
- /// The returned string will change across platforms and hosts which
- /// means that parsing it, for example, would be a
- /// platform-compatibility hazard.
- to-debug-string: func() -> string;
- }
-
/// An input bytestream.
///
/// `input-stream`s are *non-blocking* to the extent practical on underlying