Blunder v1.1.1 Blunder exception View Source

Blunder is a generic error struct

Link to this section Summary

Functions

Formats a Blunder error for printing/logging

Creates a new Blunder from a details string or another error

Creates a new Blunder with a given code and options

Runs the given function in a separate process and returns the function’s return value or {:error, Blunder.t} if the function raised an excpetion or crashed in some way (untrapped throw, process exit, etc)

Link to this section Types

Link to this type fun_return_type() View Source
fun_return_type() :: any()
Link to this type opts() View Source
opts() :: [
  code: atom(),
  details: binary(),
  summary: binary(),
  original_error: any(),
  severity: severity(),
  stacktrace: nil | Exception.stacktrace()
]
Link to this type severity() View Source
severity() :: :critical | :error | :warn | :info | :debug
Link to this type t() View Source
t() :: %Blunder{
  __exception__: term(),
  code: atom(),
  details: binary(),
  original_error: any(),
  severity: severity(),
  stacktrace: nil | Exception.stacktrace(),
  summary: binary()
}

Link to this section Functions

Formats a Blunder error for printing/logging.

This returns a verbose, multi-line string.

Creates a new Blunder from a details string or another error

Examples:

# A string will be used as details
iex> Blunder.new("These are the error details")
%Blunder{details: "These are the error details"}

# Blunder structs are returned unchanged
iex> Blunder.new(%Blunder{code: :some_code})
%Blunder{code: :some_code}

# Anything else will be used as the `original_error`
iex> Blunder.new(%RuntimeError{message: "oops!"})
%Blunder{original_error: %RuntimeError{message: "oops!"}}
Link to this function new(code, details) View Source
new(code :: atom(), binary() | opts()) :: t()

Creates a new Blunder with a given code and options.

Examples:

iex> Blunder.new(:some_code, summary: "s", details: "d")
%Blunder{code: :some_code, summary: "s", details: "d"}

# A string can be given in place of the keyword options to set just the details
iex> Blunder.new(:some_code, "These are the error details")
%Blunder{code: :some_code, details: "These are the error details"}
Link to this function trap_exceptions(fun, opts \\ []) View Source
trap_exceptions(
  fun :: (... -> fun_return_type()),
  opts :: [timeout_ms: number(), blunder: Blunder.t()]
) :: fun_return_type() | {:error, Blunder.t()}

Runs the given function in a separate process and returns the function’s return value or {:error, Blunder.t} if the function raised an excpetion or crashed in some way (untrapped throw, process exit, etc).

Options:

  • timeout - function execution will be terminated after this many ms and an error retruned. Defaults to 2_000.
  • blunder - The attributes of this Blunder will be used as defauls for the attribute of the Blunder returned when there is an exception.