n2o_error.erl 855 B

1234567891011121314151617181920212223242526272829
  1. -module(n2o_error).
  2. -include_lib("n2o/include/wf.hrl").
  3. -compile([export_all, nowarn_export_all]).
  4. -export(?FAULTER_API).
  5. % Plain Text Error Page Render
  6. % Here is sample
  7. %
  8. % ERROR: error:badarith
  9. %
  10. % STACK: index:body/0:18
  11. % index:main/0:8
  12. % n2o_document:run/1:15
  13. stack(Error, Reason) ->
  14. Stacktrace = [case A of
  15. { Module,Function,Arity,Location} ->
  16. { Module,Function,Arity,proplists:get_value(line, Location) };
  17. Else -> Else end
  18. || A <- erlang:get_stacktrace()],
  19. [Error, Reason, Stacktrace].
  20. error_page(Class,Error) ->
  21. io_lib:format("ERROR: ~w:~w~n~n",[Class,Error]) ++
  22. "STACK: " ++
  23. [ wf:render([io_lib:format("\t~w:~w/~w:~w",
  24. [ Module,Function,Arity,proplists:get_value(line, Location) ]),"\n"])
  25. || { Module,Function,Arity,Location} <- erlang:get_stacktrace() ].