Nebulex.Error exception (Nebulex v3.0.0-rc.1)

View Source

This exception represents command execution errors. For example, the cache cannot perform a command because it has not started, it does not exist, or the adapter failed to perform it for any reason.

Exception fields

See t/0.

Error reasons

The :reason field can assume the following values:

  • :timeout - if there is a timeout when executing the cache command.

  • :transaction_aborted - if a transaction execution fails and aborts.

  • :event_listener_already_exists - if another cache entry listener with the same ID already exists.

  • :event_listener_error - if a cache entry event listener fails when processing an event.

  • Exception.t/0 - if the underlying adapter fails due to an exception.

  • any/0 - the command fails with an adapter-specific error.

Summary

Types

Error reason type

t()

The type for this exception struct.

Functions

A callback invoked when a custom formatter module is provided.

Formats the error metadata when not empty.

Types

reason()

@type reason() :: atom() | {atom(), any()} | Exception.t()

Error reason type

t()

@type t() :: %Nebulex.Error{
  __exception__: true,
  metadata: keyword(),
  module: module(),
  reason: reason()
}

The type for this exception struct.

This exception has the following public fields:

  • :reason - the error reason. It can be one of the Nebulex-specific reasons described in the "Error reasons" section in the module documentation.

  • :module - a custom error formatter module. When it is present, it invokes module.format_error(reason, metadata) to format the error reason. The argument metadata is a keyword with the metadata given to the exception. See format_error/2 for more information.

  • :metadata - the metadata contains the options given to the exception excluding the :reason and :module that are part of the exception fields. For example, when raising an exception raise Nebulex.Error, reason: :test, foo: :bar, the metadata will be [foo: :bar].

Functions

format_error(reason, metadata)

@spec format_error(
  any(),
  keyword()
) :: binary()

A callback invoked when a custom formatter module is provided.

Arguments

  • reason - the error reason.
  • metadata - a keyword with the metadata given to the exception.

For example, if an adapter returns:

wrap_error Nebulex.Error,
  reason: :my_reason,
  module: MyAdapter.Formatter,
  foo: :bar

the exception invokes:

MyAdapter.Formatter.format_error(:my_reason, foo: :bar)

maybe_format_metadata(msg, metadata)

@spec maybe_format_metadata(
  binary(),
  keyword()
) :: binary()

Formats the error metadata when not empty.