Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Errors should not be swallowed #88

Merged
merged 1 commit into from

2 participants

@mcmire

If a task for a guard throws an exception, the error is swallowed. This is fine, except that if you're developing a guard, all you get is an error message without an idea of where it occurred, which is not very helpful. This change prints the exception and its backtrace to the console before continuing.

One note about this is that I didn't know whether to print to stderr or use UI.error. I don't really know what the point of the UI module is -- since it resets colors, one would think that it prints colored messages also, but it doesn't do that, so I don't exactly see why it's being used. Feel free to change it to UI.error if that's what you really want, though.

@rymai
Owner

Hi,

if it's for development purpose, I think the UI#debug method is appropriate. You would then launch guard in debug mode with guard -d (I've just seen that this option is not documented in the README!) to see more info on the exception.

@mcmire

Hmm. Yeah, UI.debug might make more sense. I could live with that.

@rymai rymai merged commit b41f31e into guard:master
@rymai
Owner

Ok, I've merged the pull-request and finally used UI.error since I think it's always useful to see an Exception trace (not only during development). I've also added color (red) to the "ERROR:" flag when you use UI.error.

Thanks Elliot!

@ghost Unknown referenced this pull request
Closed

:notification => false flag got ignored #248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 18, 2011
  1. @mcmire
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 3 deletions.
  1. +5 −3 lib/guard.rb
View
8 lib/guard.rb
@@ -59,11 +59,13 @@ def run_on_change_for_all_guards(files)
# fire it if his work leads to a system failure
def supervised_task(guard, task_to_supervise, *args)
guard.send(task_to_supervise, *args)
- rescue Exception
- UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{$!}")
+ rescue Exception => err
+ UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{err}")
+ warn "#{err.class}: #{err.message}"
+ warn err.backtrace.join("\n")
guards.delete guard
UI.info("Guard #{guard.class.name} has just been fired")
- return $!
+ return err
end
def run
Something went wrong with that request. Please try again.