Result Types
Result type for pipeline error handling — Rust-inspired Ok/Err.
Provides a discriminated union for representing success (Ok) or
failure (Err) as values that flow through pipeline channels,
instead of silently dropping errors.
Works with Python 3.12+ match/case:
match item:
case Ok(value=v):
print(f"Success: {v}")
case Err(error=e):
print(f"Failed at {e.stage}: {e.exception}")
- class anyiostream.result.PipelineError[source]
Bases:
objectContext captured when a pipeline stage raises an exception.
- item
The original input item that caused the error.
- Type:
Any
- class anyiostream.result.Ok[source]
Bases:
GenericSuccessful result wrapping a value.
- value: T
- unwrap_or(default)[source]
Return the contained value (ignores default).
- Parameters:
default (T)
- Return type:
T
- __init__(value)
- Parameters:
value (T)
- Return type:
None
- class anyiostream.result.Err[source]
Bases:
GenericError result wrapping an error.
- error: E
- __init__(error)
- Parameters:
error (E)
- Return type:
None
Rust-inspired Ok/Err discriminated union for pipeline error handling.
Ok[T]
Wraps a successful value.
from anyiostream import Ok
ok = Ok(42)
Methods
Method |
Returns |
Description |
|---|---|---|
|
|
The wrapped value |
|
|
Always true for Ok |
|
|
Always false for Ok |
|
|
Return the value |
|
|
Return the value (ignores default) |
|
raises |
Ok has no error |
|
|
Apply fn to value |
|
|
No-op for Ok |
Err[E]
Wraps an error value.
from anyiostream import Err, PipelineError
err = Err(PipelineError(exception=ValueError("boom"), item=42, stage="parse"))
Methods
Method |
Returns |
Description |
|---|---|---|
|
|
The wrapped error |
|
|
Always false for Err |
|
|
Always true for Err |
|
raises |
Err has no value |
|
|
Return the default |
|
|
Return the error |
|
|
No-op for Err |
|
|
Apply fn to error |
PipelineError
Context captured when a pipeline stage raises an exception.
from anyiostream import PipelineError
Fields
Field |
Type |
Description |
|---|---|---|
|
|
The caught exception |
|
|
The input item that caused the error |
|
|
Stage name (from |
|
|
Formatted traceback at failure point |
String Representation
str(err.error) # "[parse] ValueError: boom"
Result Type Alias
Result = Ok[T] | Err[E]
Pattern Matching
match item:
case Ok(value=v):
print(f"Success: {v}")
case Err(error=e):
print(f"Failed at {e.stage}: {e.exception}")
Both Ok and Err are frozen dataclasses with slots=True, supporting structural pattern matching in Python 3.12+.