fails<T> static method

DbError fails<T>(
  1. Result<T, DbError> result,
  2. DbErrorCode code,
  3. String what
)

result is Err with code; answers the error.

Implementation

static DbError fails<T>(
  Result<T, DbError> result,
  DbErrorCode code,
  String what,
) => result.when(
  ok: (value) => throw ConformanceFailure(
    '$what: expected ${code.name}, got Ok($value)',
  ),
  err: (error) => error.code == code
      ? error
      : throw ConformanceFailure(
          '$what: expected ${code.name}, got ${error.code.name} ($error)',
        ),
);