gloo/error

All errors returned by gloom repo functions are wrapped in GlooError.

Use map_constraint or map_constraints to convert ConstraintError into application-specific error types without losing the constraint name.

Types

pub type GlooError {
  NoResultError
  TooManyResultsError(count: Int)
  ConstraintError(name: String)
  DbError(message: String)
  RollbackError
}

Constructors

  • NoResultError
  • TooManyResultsError(count: Int)
  • ConstraintError(name: String)
  • DbError(message: String)
  • RollbackError

Values

pub fn from_sqlight(e: sqlight.Error) -> GlooError
pub fn map_constraint(
  result: Result(t, GlooError),
  constraint_name: String,
  on_match: mapped_error,
  fallback: fn(GlooError) -> mapped_error,
) -> Result(t, mapped_error)

Map a specific constraint violation to a typed error. All other errors are re-wrapped via fallback.

Example: repo.query_one(repo, q) |> error.map_constraint(“users_email_idx”, EmailAlreadyTaken, DbFailed)

pub fn map_constraints(
  result: Result(t, GlooError),
  mappings: List(#(String, mapped_error)),
  fallback: fn(GlooError) -> mapped_error,
) -> Result(t, mapped_error)

Match multiple constraint names to typed errors. Falls back for any unrecognised constraint or non-constraint error.

pub fn to_string(e: GlooError) -> String
Search Document