Skip to main content

Why Error Recovery?

Not all errors are fatal. Error recovery lets you:
  • Provide fallback values when operations fail
  • Retry operations with different strategies
  • Transform errors into successes when appropriate
  • Gracefully degrade functionality

Using orElse for Fallback

Basic Error Recovery

orElse lets you recover from an error by providing an alternative Result:

Chaining Multiple Fallbacks

Try multiple recovery strategies:

Real-World Example: Multi-Tier Data Loading

1

Define data sources

2

Implement recovery chain

3

Use with metrics

Using unwrapOr for Simple Defaults

When you just need a default value:

unwrapOr vs orElse

When you want a simple default value:

Pattern Matching with match

Complete Error Handling

match forces you to handle both success and failure:
Both callbacks must return the same type, and match unwraps the Result:

Async Pattern Matching

With ResultAsync, match returns a Promise:

Error Context and Recovery

Add context as errors flow through recovery chains:

Conditional Recovery

Recover only from specific errors:

Real-World Example: Retry with Backoff

Implement retry logic with exponential backoff:

Combining Recovery Strategies

Mix different recovery patterns:

Next Steps

Basic Usage

Review the fundamentals of Result types

Chaining Operations

Learn how to compose complex operations