expectErr method

E expectErr(
  1. String message
)

Returns the error, or throws message for an Ok.

Throws a StateError carrying message followed by the value.

final reason = const Err<int, String>('offline').expectErr('no network');

Implementation

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