lib/ruote/svc/error_handler.rb in ruote-2.1.11 vs lib/ruote/svc/error_handler.rb in ruote-2.2.0

- old
+ new

@@ -1,7 +1,7 @@ #-- -# Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com +# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -33,29 +33,29 @@ # This service is used, by the worker, the dispatch pool and some # receivers (like the one in ruote-beanstalk). # class ErrorHandler - def initialize (context) + def initialize(context) @context = context end # As used by the dispatch pool and the worker. # - def msg_handle (msg, exception) + def msg_handle(msg, exception) fexp = Ruote::Exp::FlowExpression.fetch( @context, msg['fei'] || msg['workitem']['fei'] ) rescue nil handle(msg, fexp, exception) end # As used by some receivers (see ruote-beanstalk's receiver). # - def action_handle (action, fei, exception) + def action_handle(action, fei, exception) fexp = Ruote::Exp::FlowExpression.fetch(@context, fei) msg = { 'action' => action, @@ -68,11 +68,11 @@ protected # As used by the worker. # - def handle (msg, fexp, exception) + def handle(msg, fexp, exception) wfid = msg['wfid'] || (msg['fei']['wfid'] rescue nil) fei = msg['fei'] || (fexp.h.fei rescue nil) backtrace = exception.backtrace || [] @@ -86,30 +86,38 @@ p exception puts backtrace[0, 20].join("\n") puts "..." puts puts "-- msg --" + key_length = msg.keys.collect { |k| k.length }.max + 1 msg.keys.sort.each { |k| - puts " #{k.inspect} =>\n#{msg[k].inspect}" + v = msg[k] + v = (Ruote.sid(v) rescue nil) if k == 'fei' || k == 'parent_id' + printf("%*s : %s\n", key_length, k, v.inspect) } puts "-- . --" puts end # on_error ? return if fexp && fexp.handle_on_error(msg, exception) # emit 'msg' + # + # (this message might get intercepted by a tracker) @context.storage.put_msg( 'error_intercepted', - 'error_class' => exception.class.name, - 'error_message' => exception.message, - 'error_backtrace' => exception.backtrace, - # for backward compatibility - 'message' => exception.inspect, + 'error' => { + 'fei' => fei, + 'at' => Ruote.now_to_utc_s, + 'class' => exception.class.name, + 'message' => exception.message, + 'trace' => backtrace + }, 'wfid' => wfid, + 'fei' => fei, 'msg' => msg) # fill error in the error journal @context.storage.put(