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