Skip to content

StreamError ​

StreamError is the structured error type used by recoverable stream operations.

Signatureinterface 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 ​

FieldTypePurpose
codestringStable identifier for programmatic handling.
messagestringHuman-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.