StreamError
StreamError is the structured error type used by recoverable stream operations.
Signature
interface StreamError { readonly code: string; readonly message: string }StreamError is an Error: a catch (error) without an annotation receives it, and error is StreamError narrows the binding to it, with every field of StreamError.
Fields
| Field | Type | Purpose |
|---|---|---|
code | string | Stable identifier for programmatic handling. |
message | string | Human-readable explanation. |
Usage and errors
tyrus
async function writeChunk(stream: WritableStream<u8[]>, bytes: u8[]): Promise<void> throws StreamError {
await stream.write(bytes);
}error
tyrus
async function invalid(stream: WritableStream<u8[]>): Promise<void> {
await stream.write("not bytes");
}Use throws StreamError on an enclosing function when it forwards an operation that can reject with this error.
