Packages
rambla
1.2.1
1.5.0
1.4.2
1.4.1
1.4.0
1.3.0
1.2.6
1.2.5
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.1
1.0.0
0.16.6
0.16.5
0.16.4
0.16.3
0.16.2
0.16.1
0.16.0
0.15.0
0.14.4
0.14.3
0.14.2
0.14.1
0.14.0
0.13.1
0.13.0
0.12.2
0.12.1
0.11.1
0.11.0
0.10.0
0.9.3
0.9.2
0.9.1
0.9.0
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.0
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0
Easy publishing to many different targets. Supported back-ends: - Rabbit [Amqp](https://hexdocs.pm/amqp/) - Redis [Redix](https://hexdocs.pm/redix) - Http [:httpc](http://erlang.org/doc/man/httpc.html) - Smtp [:gen_smtp](https://hexdocs.pm/gen_smtp) - Slack [Envío](https://hexdocs.pm/envio)
Current section
Files
Jump to
Current section
Files
lib/rambla/exception.ex
defmodule Rambla.Exception do
@moduledoc """
Base type for all the `Rambla` exceptions.
"""
@typedoc """
`Rambla` exception contains:
- `reason` the string describing the error in human-readable form
- `source` usually the type/action this error is originated from
- `info` free-style map containig additional information (not displayed by default)
"""
@type t :: %{
reason: any(),
source: atom(),
cause: Rambla.Exception.t() | nil
}
defmacro __using__(_opts \\ []) do
quote location: :keep do
@moduledoc false
defexception [:reason, :source, :info, :expected]
@impl true
def message(%__MODULE__{reason: reason, source: source, expected: expected}),
do: "✗ " <> inspect(source) <> ": " <> reason <> " (expected: #{expected})"
@impl true
def exception(opts) do
source = Keyword.get(opts, :source, "🤷")
reason = Keyword.get(opts, :reason, "Unexpected error (blame AM)")
info = Keyword.get(opts, :info, %{})
%__MODULE__{reason: reason, source: source, info: info}
end
defimpl Inspect do
def inspect(%type{} = data, opts), do: type.message(data)
end
end
end
@doc false
@spec reduce(exs :: [Rambla.Exception.t()]) :: binary()
def reduce(exs) do
exs
|> Enum.reverse()
|> Enum.map_join("\n", & &1.message)
end
end
defmodule Rambla.Exceptions.Connection do
@moduledoc """
The instance of generic `Rambla.Exception`, to be raised/created
when some connection issues happen.
"""
use Rambla.Exception
end
defmodule Rambla.Exceptions.Unknown do
@moduledoc """
The instance of generic `Rambla.Exception`, has no specific behaviour.
This module is introduced to simplify pattern matching / distinguishing between
different types of exceptions.
Basically, `Rambla.Exception.Unknown` is raised during compile-time,
`Rambla.Exception.Connection` is an exception caused by connection issues, etc.
"""
use Rambla.Exception
end