Table of Contents

Class Error

Namespace
Compendium.Core.Results
Assembly
Compendium.Core.dll

Represents an error that occurred during operation execution. Provides structured error information with code, message, and optional details.

public sealed class Error : ValueObject, IEquatable<ValueObject>
Inheritance
Error
Implements
Inherited Members

Constructors

Error(string, string, ErrorType, IReadOnlyDictionary<string, object>?)

Initializes a new instance of the Error class.

public Error(string code, string message, ErrorType type, IReadOnlyDictionary<string, object>? metadata = null)

Parameters

code string

The error code.

message string

The error message.

type ErrorType

The error type.

metadata IReadOnlyDictionary<string, object>

Optional metadata associated with the error.

Fields

None

Represents no error (success state).

public static readonly Error None

Field Value

Error

NullValue

Represents a null value error.

public static readonly Error NullValue

Field Value

Error

Properties

Code

Gets the error code that uniquely identifies the error type.

public string Code { get; }

Property Value

string

Message

Gets the human-readable error message.

public string Message { get; }

Property Value

string

Metadata

Gets additional metadata associated with the error.

public IReadOnlyDictionary<string, object> Metadata { get; }

Property Value

IReadOnlyDictionary<string, object>

Type

Gets the error type classification.

public ErrorType Type { get; }

Property Value

ErrorType

Methods

Conflict(string, string, IReadOnlyDictionary<string, object>?)

Creates a conflict error.

public static Error Conflict(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)

Parameters

code string

The error code.

message string

The error message.

metadata IReadOnlyDictionary<string, object>

Optional metadata.

Returns

Error

A new conflict error.

Failure(string, string, IReadOnlyDictionary<string, object>?)

Creates a failure error.

public static Error Failure(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)

Parameters

code string

The error code.

message string

The error message.

metadata IReadOnlyDictionary<string, object>

Optional metadata.

Returns

Error

A new failure error.

Forbidden(string, string, IReadOnlyDictionary<string, object>?)

Creates a forbidden error.

public static Error Forbidden(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)

Parameters

code string

The error code.

message string

The error message.

metadata IReadOnlyDictionary<string, object>

Optional metadata.

Returns

Error

A new forbidden error.

GetEqualityComponents()

Gets the equality components that define the value object's identity.

protected override IEnumerable<object?> GetEqualityComponents()

Returns

IEnumerable<object>

An enumerable of objects that participate in equality comparison.

NotFound(string, string, IReadOnlyDictionary<string, object>?)

Creates a not found error.

public static Error NotFound(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)

Parameters

code string

The error code.

message string

The error message.

metadata IReadOnlyDictionary<string, object>

Optional metadata.

Returns

Error

A new not found error.

ToString()

Returns a string representation of the error.

public override string ToString()

Returns

string

A string that represents the current error.

TooManyRequests(string, string, IReadOnlyDictionary<string, object>?)

Creates a too many requests error.

public static Error TooManyRequests(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)

Parameters

code string

The error code.

message string

The error message.

metadata IReadOnlyDictionary<string, object>

Optional metadata.

Returns

Error

A new too many requests error.

Unauthorized(string, string, IReadOnlyDictionary<string, object>?)

Creates an unauthorized error.

public static Error Unauthorized(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)

Parameters

code string

The error code.

message string

The error message.

metadata IReadOnlyDictionary<string, object>

Optional metadata.

Returns

Error

A new unauthorized error.

Unavailable(string, string, IReadOnlyDictionary<string, object>?)

Creates an unavailable error.

public static Error Unavailable(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)

Parameters

code string

The error code.

message string

The error message.

metadata IReadOnlyDictionary<string, object>

Optional metadata.

Returns

Error

A new unavailable error.

Unexpected(string, string, IReadOnlyDictionary<string, object>?)

Creates an unexpected error.

public static Error Unexpected(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)

Parameters

code string

The error code.

message string

The error message.

metadata IReadOnlyDictionary<string, object>

Optional metadata.

Returns

Error

A new unexpected error.

Validation(string, string, IReadOnlyDictionary<string, object>?)

Creates a validation error.

public static Error Validation(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)

Parameters

code string

The error code.

message string

The error message.

metadata IReadOnlyDictionary<string, object>

Optional metadata.

Returns

Error

A new validation error.

Operators

implicit operator Error(string)

Implicitly converts a string to an Error.

public static implicit operator Error(string error)

Parameters

error string

The error message.

Returns

Error