Skip to main content
Version: 2.x

Error Channel Operations

ZIO's error channel supports a rich set of transformations beyond simple recovery. These operators let us reshape, inspect, and restructure errors and successes without necessarily resolving the failure โ€” useful when threading error values through a larger computation.

  • Map Operations โ€” transform error values with mapError, mapErrorCause, and mapAttempt without recovering from the failure.
  • Chaining Effects Based on Errors โ€” sequence a second effect that depends on the first effect's typed error using flatMapError.
  • Filtering the Success Channel โ€” convert success values that fail a predicate into typed errors using filterOrFail, filterOrDie, and filterOrElse.
  • Tapping Errors โ€” inspect failure values, defects, and Cause graphs as a side effect without altering the error channel, using tapError, tapErrorCause, and tapDefect.
  • Exposing Errors in the Success Channel โ€” move typed failures into the success channel as Either values using ZIO#either, then submerge them back with ZIO#absolve.
  • Exposing the Cause in the Success Channel โ€” surface the full Cause[E] graph in the success channel using ZIO#cause, then submerge it with ZIO#uncause.
  • Converting Defects to Failures โ€” turn defects back into typed failures using absorb and resurrect.
  • Error Refinement โ€” narrow or widen the typed error channel using refineOrDie, refineToOrDie, unrefine, and unrefineTo.
  • Flattening Optional Error Types โ€” collapse Option[E] error types into plain E using ZIO#flattenErrorOption, providing a default error for the None case.
  • Merging the Error Channel into the Success Channel โ€” collapse the error channel into the success channel using ZIO#merge when both types are compatible, producing an infallible effect.
  • Flipping Error and Success Channels โ€” swap the error and success channels using flip and flipWith to apply success-channel operators to errors.
  • Rejecting Some Success Values โ€” convert select success values into typed failures using ZIO#reject and ZIO#rejectZIO with a partial function.
  • Zooming In on Nested Values โ€” navigate Option and Either values nested inside ZIO effects using some, unsome, left, right, and related operators.