From 62bb41fd350f5025f3a910c8d2b52ce44556dc71 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Mon, 9 Apr 2012 13:19:57 -0400 Subject: [PATCH] Add support for badrecord errors --- src/error_logger_lager_h.erl | 2 ++ test/crash.erl | 8 ++++++++ test/lager_test_backend.erl | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index cfe2667..88fc2d3 100644 --- a/src/error_logger_lager_h.erl +++ b/src/error_logger_lager_h.erl @@ -202,6 +202,8 @@ format_reason({bad_return_value, Val}) -> ["bad return value: ", print_val(Val)]; format_reason({{bad_return_value, Val}, MFA}) -> ["bad return value: ", print_val(Val), " in ", format_mfa(MFA)]; +format_reason({{badrecord, Record}, [MFA|_]}) -> + ["bad record ", print_val(Record), " in ", format_mfa(MFA)]; format_reason({{case_clause, Val}, [MFA|_]}) -> ["no case clause matching ", print_val(Val), " in ", format_mfa(MFA)]; format_reason({function_clause, [MFA|_]}) -> diff --git a/test/crash.erl b/test/crash.erl index 7037379..25084e9 100644 --- a/test/crash.erl +++ b/test/crash.erl @@ -9,6 +9,11 @@ -export([start/0]). +-record(state, { + host, + port + }). + start() -> gen_server:start({local, ?MODULE}, ?MODULE, [], []). @@ -49,6 +54,9 @@ handle_call(try_clause, _, State) -> handle_call(badmatch, _, State) -> {A, B, C} = State, {reply, [A, B, C], State}; +handle_call(badrecord, _, State) -> + Host = State#state.host, + {reply, Host, State}; handle_call(function_clause, _, State) -> {reply, function(State), State}; handle_call(badarith, _, State) -> diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index b25e03f..3de7bd2 100644 --- a/test/lager_test_backend.erl +++ b/test/lager_test_backend.erl @@ -404,6 +404,15 @@ error_logger_redirect_crash_test_() -> test_body(Expected, lists:flatten(Msg)) end }, + {"bad record", + fun() -> + Pid = whereis(crash), + crash(badrecord), + {_, _, Msg} = pop(), + Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: bad record state in crash:handle_call/3", [Pid])), + test_body(Expected, lists:flatten(Msg)) + end + }, {"noproc", fun() -> Pid = whereis(crash),