Table of Contents

Class Error

Namespace
Trellis
Assembly
Trellis.Core.dll

Closed discriminated union of error values. Each case is a nested sealed record that mirrors a status from the IANA HTTP Status Code Registry (RFC 9110, RFC 6585) and carries a strongly-typed payload describing what went wrong.

public abstract record Error : IEquatable<Error>
Inheritance
Error
Implements
Derived
Inherited Members
Extension Methods

Remarks

Closure. The base record has a private constructor; only nested cases declared in this file may inherit from Error. External code cannot extend the catalog, so switch over an Error reference is exhaustive at the language level.

Identity. Kind is a stable, IANA-aligned slug (e.g. "not-found") that survives CLR renames. Code defaults to Kind and is overridden by cases whose payload carries a per-instance reason code (for example Error.Conflict returns its ReasonCode).

Detail. Every case inherits an optional Detail property from the base. Callers supply it via object-initializer syntax: new Error.NotFound(resource) { Detail = "..." }. The boundary renderer prefers Detail when present; otherwise it computes a localized message from Kind, Code, and the typed payload.

Equality. Value-based equality over the discriminator, the typed payload, and Detail. Cause is intentionally excluded from equality so that two errors with identical surface payload compare equal regardless of how deeply they were wrapped — see the Equals(Error?) override for the rationale. Collection-bearing payloads use EquatableArray<T> for sequence equality.

Cause chain. Cause is a structured chain (never a live Exception). Cycles are detected at init time and throw InvalidOperationException.

Properties

Cause

Gets the optional structured cause of this error. Never holds a live Exception; use a child Error to attach causal context.

public Error? Cause { get; init; }

Property Value

Error

Code

Gets the per-instance machine-readable code. Defaults to Kind; cases whose payload carries a per-instance ReasonCode override this.

public virtual string Code { get; }

Property Value

string

Detail

Gets the optional human-readable detail. When non-null the boundary renderer prefers this over the default template for Code.

public string? Detail { get; init; }

Property Value

string

Kind

Gets the stable, IANA-aligned identifier for this case (e.g. "not-found", "unprocessable-content"). Suitable for telemetry, problem-details type URI synthesis, and wire serialization.

public abstract string Kind { get; }

Property Value

string

Methods

Equals(Error?)

Value equality over the discriminator (Trellis.Error.EqualityContract) and Detail, plus each derived case's positional payload. Cause is intentionally excluded from equality and hashing — two errors with identical kind, payload, and detail represent the same logical failure regardless of how deeply they were wrapped. This mirrors Exception, whose equality does not recurse into InnerException, and keeps test assertions ergonomic (callers assert on the surface error without reconstructing the entire causal chain).

public virtual bool Equals(Error? other)

Parameters

other Error

Returns

bool

GetDisplayMessage()

Returns a human-readable message suitable for logging, tracing, and diagnostic surfaces. Prefers the explicit Detail when set; otherwise flattens any per-field violation messages (for Error.UnprocessableContent) before falling back to Code.

public virtual string GetDisplayMessage()

Returns

string

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.