Skip to content

Commit f1cc147

Browse files
committed
refactor: avoid introspecting error-context
This seems to be better aligned with latest specification on error context https://github.com/WebAssembly/component-model/blob/cbdd15d9033446558571824af52a78022aaa3f58/design/mvp/Explainer.md#error-context-type > A consequence of this, however, is that components *must not* depend on the > contents of `error-context` values for behavioral correctness. In particular, > case analysis of the contents of an `error-context` should not determine > *error recovery*; explicit `result` or `variant` types must be used in the > function return type instead (e.g., > `(func (result (tuple (stream u8) (future $my-error)))`). Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent d23ba6e commit f1cc147

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

wit-0.3.0-draft/types.wit

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,16 @@ interface types {
299299
/// Multiple read, write, and append streams may be active on the same open
300300
/// file and they do not interfere with each other.
301301
///
302+
/// This function returns a future, which will resolve to an optional error code,
303+
/// if reading full contents of the file fails.
304+
/// The future resolves to `none` once full contents of the file are read successfully.
305+
///
302306
/// Note: This is similar to `pread` in POSIX.
303307
@since(version = 0.3.0)
304308
read: func(
305309
/// The offset within the file at which to start reading.
306310
offset: filesize,
307-
) -> result<stream<u8>, error-code>;
311+
) -> result<tuple<stream<u8>, future<option<error-code>>>, error-code>;
308312

309313
/// Return a stream for writing to a file, if available.
310314
///
@@ -314,22 +318,31 @@ interface types {
314318
/// extent of the write, with bytes between the previous end and the start of
315319
/// the write set to zero.
316320
///
321+
/// This function returns a future, which will resolve to an optional error code,
322+
/// if writing full contents of the stream fails.
323+
/// The future resolves to `none` once full contents of the stream are written successfully.
324+
///
317325
/// Note: This is similar to `pwrite` in POSIX.
318326
@since(version = 0.3.0)
319327
write: func(
320328
/// Data to write
321329
data: stream<u8>,
322330
/// The offset within the file at which to start writing.
323331
offset: filesize,
324-
) -> result<_, error-code>;
332+
) -> result<future<option<error-code>>, error-code>;
325333

326334
/// Return a stream for appending to a file, if available.
327335
///
328336
/// May fail with an error-code describing why the file cannot be appended.
329337
///
338+
/// This function returns a future, which will resolve to an optional error code,
339+
/// if writing full contents of the stream fails.
340+
/// The future resolves to `none` once full contents of the stream are written successfully.
341+
///
342+
///
330343
/// Note: This is similar to `write` with `O_APPEND` in POSIX.
331344
@since(version = 0.3.0)
332-
append: func(data: stream<u8>) -> result<_, error-code>;
345+
append: func(data: stream<u8>) -> result<future<option<error-code>>, error-code>;
333346

334347
/// Provide file advisory information on a descriptor.
335348
///
@@ -620,17 +633,4 @@ interface types {
620633
@since(version = 0.2.0)
621634
read-directory-entry: func() -> result<option<directory-entry>, error-code>;
622635
}
623-
624-
/// Attempts to extract a filesystem-related `error-code` from the stream
625-
/// `error-context` provided.
626-
///
627-
/// Stream operations which return `stream-error::last-operation-failed`
628-
/// have a payload with more information about the operation that failed.
629-
/// This payload can be passed through to this function to see if there's
630-
/// filesystem-related information about the error to return.
631-
///
632-
/// Note that this function is fallible because not all stream-related
633-
/// errors are filesystem-related errors.
634-
@since(version = 0.3.0)
635-
filesystem-error-code: func(err: error-context) -> option<error-code>;
636636
}

0 commit comments

Comments
 (0)