PageRenderTime 41ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/error.erl

https://github.com/3lectrologos/Concuerror
Erlang | 71 lines | 43 code | 15 blank | 13 comment | 0 complexity | 2a5d06bad572da96cb414378bf90d8cc MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %%%----------------------------------------------------------------------
  2. %%% Copyright (c) 2011, Alkis Gotovos <el3ctrologos@hotmail.com>,
  3. %%% Maria Christakis <mchrista@softlab.ntua.gr>
  4. %%% and Kostis Sagonas <kostis@cs.ntua.gr>.
  5. %%% All rights reserved.
  6. %%%
  7. %%% This file is distributed under the Simplified BSD License.
  8. %%% Details can be found in the LICENSE file.
  9. %%%----------------------------------------------------------------------
  10. %%% Authors : Alkis Gotovos <el3ctrologos@hotmail.com>
  11. %%% Maria Christakis <mchrista@softlab.ntua.gr>
  12. %%% Description : Error interface
  13. %%%----------------------------------------------------------------------
  14. -module(error).
  15. -export([long/1, mock/0, new/1, short/1, type/1]).
  16. -export_type([error/0]).
  17. -include("gen.hrl").
  18. -type error_type() :: 'assertion_violation' | 'deadlock' | 'exception'.
  19. -type error() :: {error_type(), term()}.
  20. -spec new(term()) -> error().
  21. new({deadlock, _Set} = Deadlock) -> Deadlock;
  22. new({{assertion_failed, Details}, _Any}) -> {assertion_violation, Details};
  23. new({{assertEqual_failed, Details}, _Any}) -> {assertion_violation, Details};
  24. new(Reason) -> {exception, Reason}.
  25. -spec type(error()) -> nonempty_string().
  26. type({deadlock, _Blocked}) -> "Deadlock";
  27. type({assertion_violation, _Details}) -> "Assertion violation";
  28. type({exception, _Details}) -> "Exception".
  29. -spec short(error()) -> nonempty_string().
  30. short({deadlock, Blocked}) ->
  31. OldList = lists:sort(?SETS:to_list(Blocked)),
  32. {List, [Last]} = lists:split(length(OldList) - 1, OldList),
  33. Fun = fun(L, A) -> A ++ lid:to_string(L) ++ ", " end,
  34. lists:foldl(Fun, "", List) ++ lid:to_string(Last);
  35. short({assertion_violation, [{module, Module}, {line, Line}|_Rest]}) ->
  36. util:flat_format("~p.erl:~p", [Module, Line]);
  37. short({exception, Reason}) ->
  38. lists:flatten(io_lib:format("~W", [Reason, 3])).
  39. -spec long(error()) -> nonempty_string().
  40. long({deadlock, _Blocked} = Error) ->
  41. Format = "Error type : Deadlock~n"
  42. "Blocked processes : ~s",
  43. util:flat_format(Format, [short(Error)]);
  44. long({assertion_violation,
  45. [{module, Module}, {line, Line}, _Xpr, {expected, Exp}, {value, Val}]}) ->
  46. Format = "Error type : Assertion violation~n"
  47. "Module:Line : ~p.erl:~p~n"
  48. "Expected : ~p~n"
  49. "Value : ~p",
  50. util:flat_format(Format, [Module, Line, Exp, Val]);
  51. long({exception, Details}) ->
  52. Format = "Error type : Exception~n"
  53. "Details : ~p",
  54. util:flat_format(Format, [Details]).
  55. -spec mock() -> {'exception', 'foobar'}.
  56. mock() -> {exception, foobar}.