Splode behaviour (splode v0.3.0)

View Source

Use this module to create your error aggregator and handler.

For example:

defmodule MyApp.Errors do
  use Splode, error_classes: [
    invalid: MyApp.Errors.Invalid,
    unknown: MyApp.Errors.Unknown
  ],
  unknown_error: MyApp.Errors.Unknown.Unknown
end

Options

  • :error_classes - A keyword list mapping error class atoms to error class modules. At least one error class must be provided.

  • :unknown_error - The module to use when an error cannot be converted to a known type. This is required.

  • :merge_with - A list of other Splode modules whose errors should be recognized and flattened when combined. Optional.

  • :filter_stacktraces - A list of modules or module prefixes to filter from stacktraces. For each consecutive sequence of frames matching any filter, only the deepest (last) frame is kept. This is useful for hiding internal implementation details from error stacktraces. Accepts atoms (exact module match) or strings (prefix match). Optional.

    Elixir standard library frames (Enum, Stream, List, Map, etc.) are treated as part of an active matching sequence but are not kept as the "deepest" frame. This prevents stdlib frames from appearing in filtered stacktraces when they're sandwiched between internal module calls.

    defmodule MyApp.Errors do
      use Splode,
        error_classes: [invalid: MyApp.Errors.Invalid],
        unknown_error: MyApp.Errors.Unknown,
        filter_stacktraces: [MyApp.Internal, "MyApp.Internal."]
    end

Summary

Callbacks

Converts a combination of a module and json input into an Splode exception.

Sets the path on the error or errors

Returns true if the given value is a splode error.

Combine errors into an error class

Turns any value into a splode error

Callbacks

from_json(module, map)

@callback from_json(module(), map()) :: Splode.Error.t()

Converts a combination of a module and json input into an Splode exception.

This allows for errors to be serialized and deserialized

set_path(arg1, arg2)

@callback set_path(Splode.Error.t() | [Splode.Error.t()], term() | [term()]) ::
  Splode.Error.t() | [Splode.Error.t()]

Sets the path on the error or errors

splode_error?(term)

@callback splode_error?(term()) :: boolean()

Returns true if the given value is a splode error.

to_class(any)

@callback to_class(any()) :: Splode.Error.t()

Combine errors into an error class

to_error(any)

@callback to_error(any()) :: Splode.Error.t()

Turns any value into a splode error