Created
September 25, 2012 19:28
-
-
Save steve9001/3783926 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Exception | |
def pretty | |
trace = backtrace.select{ |l|l.start_with?(Rails.root.to_s) }.join("\n ") | |
"#{self.class}\n#{message}\n#{trace}\n" | |
end | |
end |
Well by putting it on Exception you can use it in arbitrary exception handling:
task :do_stuff do
User.all.each do |user|
begin
user.wow!
rescue e
Airbrake.notify "User id: #{user.id}\n#{e.pretty}"
end
end
end
Right, or
task :do_stuff do
User.all.each do |user|
begin
user.wow!
rescue e
Airbrake.notify "User id: #{user.id}\n#{PrettyException.new(e)}"
end
end
end
Ah I get it. Yes you could I think. Personally I'm not always opposed to adding methods to an object, so e.pretty would be fine with me. I haven't used SImpleDelegator before though, that's useful.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That is nice. So you would then call
e.pretty
instead?Could you do this instead?