Failure class
Represents a failure in an operation, usually as the Left value of an Either.
Contains a human-readable error message, optional machine-readable code, and optional structured details.
- Annotations
-
- @immutable
Constructors
-
Failure([String message = 'An unexpected error occurred.', String? code, Map<
String, dynamic> details = const {}]) -
Creates a Failure with an optional
message. Defaults to a generic error message.const - Failure.fromError(Object error, [StackTrace? stackTrace])
-
Wraps a caught
erroras a Failure.factory
Properties
- code → String?
-
An optional stable code for programmatic error handling.
final
-
details
→ Map<
String, dynamic> -
Optional structured metadata describing the failure.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- message → String
-
The error message describing the failure.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
copyWith(
{String? message, String? code, Map< String, dynamic> ? details}) → Failure - Returns a copy with the given fields replaced.
-
detail<
T> (String key) → T? -
Reads a details entry as
T, ornullwhen absent or mistyped. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
-
withDetail(
String key, Object? value) → Failure - Returns a copy with one extra entry in details.
-
withDetails(
Map< String, dynamic> extra) → Failure -
Returns a copy with
extramerged into details.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override