Merge remote-tracking branch 'canonical/next'
[sinan.git] / src / sin_exceptions.erl
blob18cf2d3d15a531ac3aad78ee3360f2fbc7de8b53
1 %% -*- mode: Erlang; fill-column: 80; comment-column: 75; -*-
2 %%%---------------------------------------------------------------------------
3 %%% @author Eric Merritt
4 %%% @doc
5 %%% A utility to help format sinan exceptions
6 %%% @end
7 %%% @copyright 2011 Erlware
8 %%%---------------------------------------------------------------------------
9 -module(sin_exceptions).
11 %% API
12 -export([format_exception/1]).
13 -export_type([reason/0, exception/0]).
16 %%====================================================================
17 %% Public Types
18 %%====================================================================
20 -type reason() :: {atom(), string()} | atom().
21 -type exception() :: {module(), non_neg_integer(), reason()}.
23 %%====================================================================
24 %% API
25 %%====================================================================
27 %% @doc a helper function to format sinan formated exceptions
28 -spec format_exception(exception()) -> string().
29 format_exception({pe, _, {Module, Line, {Reason, Description}}})
30 when is_list(Reason) ->
31 io_lib:format("~s:~p [~p] ~s", [Module, Line, Reason,
32 lists:flatten(Description)]);
33 format_exception({pe, _, {Module, Line, Reason}}) ->
34 io_lib:format("~s:~p [~p]", [Module, Line, Reason]).