lode/error

Error types for lode.

Ecto raises exceptions (Ecto.NoResultsError, Ecto.StaleEntryError, …) and uses {:error, _} tuples. We unify on Result(a, LodeError) everywhere; there are no bang/! variants and nothing is raised.

Types

pub type ConstraintKind {
  Unique
  ForeignKey
  Check
  Exclusion
  NotNull
}

Constructors

  • Unique
  • ForeignKey
  • Check
  • Exclusion
  • NotNull

A single changeset/cast error: a message plus metadata key/value pairs (e.g. [#("validation", "required")]), mirroring Ecto’s error keyword lists.

pub type FieldError {
  FieldError(message: String, meta: List(#(String, String)))
}

Constructors

  • FieldError(message: String, meta: List(#(String, String)))

The top-level error returned by repo/adapter operations.

pub type LodeError {
  ChangesetInvalid(errors: List(#(String, FieldError)))
  ConstraintError(
    kind: ConstraintKind,
    name: String,
    message: String,
  )
  NoResults
  MultipleResults(count: Int)
  StaleEntry
  CastError(field: String, type_name: String, message: String)
  AdapterError(detail: String)
  QueryError(message: String)
  MultiError(step: String, reason: LodeError)
}

Constructors

  • ChangesetInvalid(errors: List(#(String, FieldError)))

    One or more changeset validations failed. Carries the per-field errors.

  • ConstraintError(
      kind: ConstraintKind,
      name: String,
      message: String,
    )

    A unique/foreign-key/check/exclusion constraint was violated.

  • NoResults

    get!/one!-style “expected exactly one row” violations.

  • MultipleResults(count: Int)

    More rows than expected were returned.

  • StaleEntry

    Optimistic-lock / stale write: the row no longer matches the filters.

  • CastError(field: String, type_name: String, message: String)

    A value could not be cast/loaded/dumped for the given field+type.

  • AdapterError(detail: String)

    The underlying adapter/driver failed. detail is driver-specific.

  • QueryError(message: String)

    A query was malformed before it reached the adapter.

  • MultiError(step: String, reason: LodeError)

    A named step in an Ecto.Multi failed; carries the step name and the underlying error through the transaction’s rollback channel.

Values

pub fn constraint_kind_to_string(kind: ConstraintKind) -> String
pub fn prefix_child_errors(
  assoc assoc: String,
  index index: Int,
  errors errors: List(#(String, FieldError)),
) -> List(#(String, FieldError))

Re-key one nested child changeset’s errors with the association that owns it — the flat nested-error convention shared with join_row_checked link errors: each error becomes "<assoc>.<field>" and gains association and child_index metadata (index is the child’s 0-based position in the list given to put_assoc/cast_assoc), so a caller holding a flat ChangesetInvalid can tell which association and which child produced each error.

Search Document