From 369d62ee1a75a0da73ff096d92f86bbadcd25ec9 Mon Sep 17 00:00:00 2001 From: Todd Lipcon Date: Wed, 23 Jan 2008 22:56:52 -0500 Subject: [PATCH] Change exception catching in generated Erlang to properly report function_clause and undef errors Summary: - The exception handler now uses erlang:get_stacktrace() and inspects that to determine whether the undef or function_clause error was actually due to the handler not implementing the function or whether it was deeper down. - The exception handler also uses error_logger:error_msg to report any exceptions, including stacktrace. - This makes debugging a lot easier. Test Plan: - I've been using this on one of our services and it works as expected --- compiler/cpp/src/generate/t_erl_generator.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler/cpp/src/generate/t_erl_generator.cc b/compiler/cpp/src/generate/t_erl_generator.cc index 02d7361..ad11629 100644 --- a/compiler/cpp/src/generate/t_erl_generator.cc +++ b/compiler/cpp/src/generate/t_erl_generator.cc @@ -1013,17 +1013,17 @@ void t_erl_generator::generate_process_function(t_service* tservice, // catch errors in the handler indent(f_service_) << "catch" << endl << - indent() << " _:Kind when Kind == undef; Kind == function_clause ->" << endl << - indent() << " X = tApplicationException:new(?tApplicationException_HANDLER_ERROR, \"Handler doesn't implement " - << tfunction->get_name() <<"\")," << endl << - - indent() << " ?R3(Oprot, writeMessageBegin, \"" << tfunction->get_name() << "\", ?tMessageType_EXCEPTION, Seqid)," << endl << - indent() << " tApplicationException:write(X, Oprot)," << endl << - indent() << " {error, X};" << endl << - indent() << " _:_Kind ->" << endl << - indent() << " X = tApplicationException:new(?tApplicationException_HANDLER_ERROR, \"Unknown handler error in " - << tfunction->get_name() << "\")," << endl << - + indent() << " Error:Kind ->" << endl << + indent() << " Stack = erlang:get_stacktrace()," << endl << + indent() << " ExceptionReason = case {Error, Kind, hd(Stack)} of" << endl << + indent() << " {_, Kind, {HandlerModule, " << tfunction->get_name() << ", _HandlerArgs}} when " << + "Kind == undef; Kind == function_clause ->" << endl << + indent() << " \"Handler doesn't implement " << tfunction->get_name() << "\";" << endl << + indent() << " _Else ->" << endl << + indent() << " \"Unknown handler error in " << tfunction->get_name() << "\"" << endl << + indent() << " end," << endl << + indent() << " error_logger:error_msg(\"Error processing " << tfunction->get_name() << ": ~p~n\", [{Error, Kind, Stack}])," << endl << + indent() << " X = tApplicationException:new(?tApplicationException_HANDLER_ERROR, ExceptionReason)," << endl << indent() << " ?R3(Oprot, writeMessageBegin, \"" << tfunction->get_name() << "\", ?tMessageType_EXCEPTION, Seqid)," << endl << indent() << " tApplicationException:write(X, Oprot)," << endl << indent() << " {error, X}" << endl; -- 2.11.4.GIT