This repository was archived by the owner on Nov 25, 2025. It is now read-only.
generated from WebAssembly/wasi-proposal-template
-
Notifications
You must be signed in to change notification settings - Fork 21
stdio: Update interfaces to support error results #82
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,59 @@ | ||
| @since(version = 0.3.0-rc-2025-08-15) | ||
| interface stdio { | ||
| @since(version = 0.3.0-rc-2025-08-15) | ||
| enum error-code { | ||
| /// Input/output error | ||
| io, | ||
| /// Invalid or incomplete multibyte or wide character | ||
| illegal-byte-sequence, | ||
| /// Broken pipe | ||
| pipe, | ||
| } | ||
| } | ||
|
|
||
| @since(version = 0.3.0-rc-2025-08-15) | ||
| interface stdin { | ||
| /// Return a stream for reading from stdin. | ||
| /// | ||
| /// This function returns a stream which provides data read from stdin, | ||
| /// and a future to signal read results. | ||
| /// | ||
| /// If the stream's readable end is dropped the future will resolve to success. | ||
lann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// | ||
| /// If the stream's writable end is dropped the future will either resolve to | ||
| /// success if stdin was closed by the writer or to an error-code if reading | ||
| /// failed for some other reason. | ||
| /// | ||
| /// Multiple streams may be active at the same time. The behavior of concurrent | ||
| /// reads is implementation-specific. | ||
| @since(version = 0.3.0-rc-2025-08-15) | ||
| get-stdin: func() -> stream<u8>; | ||
| read-via-stream: func() -> tuple<stream<u8>, future<result<_, error-code>>>; | ||
| } | ||
|
|
||
| @since(version = 0.3.0-rc-2025-08-15) | ||
| interface stdout { | ||
| /// Write the given stream to stdout. | ||
| /// | ||
| /// If the stream's writable end is dropped this function will either return | ||
| /// success once the entire contents of the stream have been written or an | ||
| /// error-code representing a failure. | ||
| /// | ||
| /// Otherwise if there is an error the readable end of the stream will be | ||
| /// dropped and this function will return an error-code. | ||
| @since(version = 0.3.0-rc-2025-08-15) | ||
| set-stdout: func(data: stream<u8>); | ||
| write-via-stream: async func(data: stream<u8>) -> result<_, error-code>; | ||
| } | ||
|
|
||
| @since(version = 0.3.0-rc-2025-08-15) | ||
| interface stderr { | ||
| /// Write the given stream to stderr. | ||
| /// | ||
| /// If the stream's writable end is dropped this function will either return | ||
| /// success once the entire contents of the stream have been written or an | ||
| /// error-code representing a failure. | ||
| /// | ||
| /// Otherwise if there is an error the readable end of the stream will be | ||
| /// dropped and this function will return an error-code. | ||
| @since(version = 0.3.0-rc-2025-08-15) | ||
| set-stderr: func(data: stream<u8>); | ||
| write-via-stream: async func(data: stream<u8>) -> result<_, error-code>; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
pipeis already expressible, bystream.writereturningcopy-result.dropped.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, is it the case that
copy-result.droppedmeans the stream is over, and that's when the error code is delivered, so we need apipe-like code for distinguishing that case from others?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for reading
droppedis eos. I'm not sure what the intent is for writes but the docs say it "doesn't signify an error." 🤷