You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's a common mistake to forget that around advice needs to return something appropriate. For example, the following method-tracing advice block probably doesn't do what you intended:
p "entering #{join_point.inspect}"
join_point.proceed
p "leaving #{join_point.inspect}"
It looks simple enough, but the block will return the result of p, which is nil, rather than the result
of calling proceed.
This new advice type would capture internally whatever proceed returned and use that value as the result after the block finishes. It would allow the above advice to work as intended.
I'm not sure this is the best solution to this common problem, but I've made this mistake too, so it's easy to do!
The text was updated successfully, but these errors were encountered:
Yes this is definitely a gotcha I ran into and for AOP newbies can make it confusing to work out what is going on.
An alternative option might be to allow an advised object to implements a return_on_advise(jp, obj, args) method that is called if around
May not work. May just have to make this type of example prominent and live with errors from time to time.
Date:2008-02-28 15:02
Priority:1
Submitted By:Dean Wampler (deanwampler)
Assigned To:Dean Wampler (deanwampler)
Category:Advice handling
State:Open
Summary:Add
:around_and_return
advice?Detailed description
It's a common mistake to forget that around advice needs to return something appropriate. For example, the following method-tracing advice block probably doesn't do what you intended:
It looks simple enough, but the block will return the result of
p
, which is nil, rather than the resultof calling
proceed
.This new advice type would capture internally whatever proceed returned and use that value as the result after the block finishes. It would allow the above advice to work as intended.
I'm not sure this is the best solution to this common problem, but I've made this mistake too, so it's easy to do!
The text was updated successfully, but these errors were encountered: