Skip to content

Commit

Permalink
Workitem.error holds the error when on_error. Thanks Oleg.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Apr 20, 2010
1 parent db6a0a4 commit 2a94e42
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -4,6 +4,7 @@

== ruote - 2.1.10 not yet released

- Workitem.error holds the error when on_error. Thanks Oleg.
- Workitem#error and Workitem#timed_out shortcuts
- participant :on_error => 'x' broken. Fixed. Thanks Oleg.
- Engine#workitem(fei) for advanced users
Expand Down
2 changes: 2 additions & 0 deletions TODO.txt
Expand Up @@ -199,6 +199,8 @@
[o] Rdoc Ruote::Engine.register_participant -> passing a block to a participant
and perhaps also on
http://ruote.rubyforge.org/implementing_participants.html (Avish)
[x] wrap workitem in process error ? for on_error consumption (thanks Oleg)
doing workitem.fields['__error__'] = [ fei, time, error_message ]

[ ] exp : exp (restricted form of eval ?)
[ ] exp : case (is it necessary ?)
Expand Down
6 changes: 4 additions & 2 deletions lib/ruote/exp/flowexpression.rb
Expand Up @@ -390,6 +390,7 @@ def cancel (flavour)
def do_fail (msg)

@h['state'] = 'failing'
@h['applied_workitem']['fields']['__error__'] = msg['error']

if h.children.size < 1
reply_to_parent(@h['applied_workitem'])
Expand Down Expand Up @@ -473,7 +474,7 @@ def lookup_on_error

# Looks up parent with on_error attribute and triggers it
#
def handle_on_error
def handle_on_error (error)

return false if h.state == 'failing'

Expand All @@ -490,7 +491,8 @@ def handle_on_error
@context.storage.put_msg(
'fail',
'fei' => oe_parent.h.fei,
'error_fei' => h.fei)
'error' => [
h.fei, Ruote.now_to_utc_s, error.class.to_s, error.message ])

true # yes, error is being handled.
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruote/worker.rb
Expand Up @@ -129,7 +129,7 @@ def handle_exception (msg, fexp, ex)
fexp = Ruote::Exp::FlowExpression.fetch(@context, fei)
end

return if fexp && fexp.handle_on_error
return if fexp && fexp.handle_on_error(ex)

# emit 'msg'

Expand Down
10 changes: 9 additions & 1 deletion test/functional/ft_5_on_error.rb
Expand Up @@ -157,13 +157,19 @@ def test_participant_on_error
pdef = Ruote.process_definition do
troublemaker :on_error => 'handle_error'
define 'handle_error' do
echo 'err...'
troublespotter
end
end

error = nil

@engine.register_participant :troublemaker do
raise 'Beijing, we have a problem !'
end
@engine.register_participant :troublespotter do |workitem|
error = workitem.error
@tracer << 'err...'
end

#noisy

Expand All @@ -175,6 +181,8 @@ def test_participant_on_error
#puts er.trace

assert_equal 'err...', @tracer.to_s
assert_equal 4, error.size
assert_equal 'RuntimeError', error[2]
end
end

0 comments on commit 2a94e42

Please sign in to comment.