postgleam/error

Types

Errors that can occur during postgleam operations

pub type Error {
  PgError(
    fields: PgErrorFields,
    connection_id: option.Option(Int),
    query: option.Option(String),
  )
  ConnectionError(message: String)
  AuthenticationError(message: String)
  EncodeError(message: String)
  DecodeError(message: String)
  ProtocolError(message: String)
  SocketError(message: String)
  TimeoutError
  PoolTimeout
}

Constructors

  • PgError(
      fields: PgErrorFields,
      connection_id: option.Option(Int),
      query: option.Option(String),
    )

    A PostgreSQL error response

  • ConnectionError(message: String)

    Connection-level error

  • AuthenticationError(message: String)

    Authentication failed

  • EncodeError(message: String)

    Error encoding parameters

  • DecodeError(message: String)

    Error decoding results

  • ProtocolError(message: String)

    Protocol violation or unexpected message

  • SocketError(message: String)

    TCP/socket error

  • TimeoutError

    Operation timed out

  • PoolTimeout

    No pool connection became free within queue_timeout

PostgreSQL error/notice fields from the wire protocol

pub type PgErrorFields {
  PgErrorFields(
    severity: String,
    code: String,
    message: String,
    detail: option.Option(String),
    hint: option.Option(String),
    position: option.Option(String),
    internal_position: option.Option(String),
    internal_query: option.Option(String),
    where_: option.Option(String),
    schema: option.Option(String),
    table: option.Option(String),
    column: option.Option(String),
    data_type: option.Option(String),
    constraint: option.Option(String),
    file: option.Option(String),
    line: option.Option(String),
    routine: option.Option(String),
  )
}

Constructors

Values

pub fn is_foreign_key_violation(err: Error) -> Bool

Whether the server refused a change because of a foreign key (SQLSTATE 23503).

pub fn is_serialization_failure(err: Error) -> Bool

Whether the transaction lost to a concurrent one and is worth running again: a serialization failure (40001) or a deadlock (40P01).

pub fn is_unique_violation(err: Error) -> Bool

Whether the server refused a row because it would break a unique constraint or primary key (SQLSTATE 23505).

pub fn parse_error_fields(
  fields: dict.Dict(String, String),
) -> PgErrorFields

Parse a raw error field dict (from wire protocol) into structured PgErrorFields

pub fn sqlstate(err: Error) -> Result(String, Nil)

The five-character SQLSTATE code of an error the server reported, such as "23505". Error(Nil) for errors that didn’t come from the server.

pub fn to_string(err: Error) -> String

A one-line human-readable description of an error.

✨ Search Document