unwrapErr method

E unwrapErr()

Returns the error, or throws for an Ok.

Throws a StateError naming the value. Mostly useful in tests.

final reason = const Err<int, String>('offline').unwrapErr(); // offline

Implementation

E unwrapErr() {
  return switch (this) {
    Ok<T, E>(:final value) =>
      throw StateError('called unwrapErr() on Ok: $value'),
    Err<T, E>(:final error) => error,
  };
}