rchampourlier / guard-shotgun

Guard gem for Sinatra (shotgun-like)
MIT License
11 stars 9 forks source link

guard-shotgun ceases restarting server upon changes if an exception is raised #5

Closed duncan-bayne closed 11 years ago

duncan-bayne commented 11 years ago

If I raise an unhandled exception in my service code, guard-shotgun fails to respond to further changes to the code.

E.g. the following sequence of events:

  1. start guard
  2. make config.ru raise an exception
  3. fix config.ru

... should (I think) cause the server to restart with the fixed code from step 3. However, it doesn't:

$ be guard
11:09:35 - INFO - Guard uses NotifySend to send notifications.
11:09:35 - INFO - Guard uses TerminalTitle to send notifications.
11:09:35 - INFO - Guard is now watching at '/home/duncan/skeleton'
11:09:35 - INFO - Guard::RSpec is running
11:09:35 - INFO - Running all specs
.

Finished in 0.0005 seconds
1 example, 0 failures
2;[RSpec results] 1 examples, 0 failures
11:09:37 - INFO - Starting up Rack...
[2013-06-11 11:09:38] INFO  WEBrick 1.3.1
[2013-06-11 11:09:38] INFO  ruby 1.9.3 (2013-02-22) [x86_64-linux]
[2013-06-11 11:09:38] INFO  WEBrick::HTTPServer#start: pid=15266 port=9292
2;[guard-shotgun] Sinatra up and running
11:09:50 - INFO - Restarting Rack without waiting...
11:09:50 - INFO - Shutting down Rack without waiting...
11:09:50 - INFO - Starting up Rack...
/home/duncan/skeleton/config.ru:1:in `block in <main>': hell (RuntimeError)
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
    from /home/duncan/skeleton/config.ru:in `new'
    from /home/duncan/skeleton/config.ru:in `<main>'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/server.rb:250:in `start'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/lib/rack/server.rb:141:in `start'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/gems/rack-1.5.2/bin/rackup:4:in `<top (required)>'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/bin/rackup:19:in `load'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/bin/rackup:19:in `<main>'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
    from /home/duncan/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `<main>'

The failing config.ru is:

raise 'hell'

# can't use require_relative here because https://github.com/rack/rack/issues/115
require File.dirname(__FILE__) + '/api/calculator_api'
require File.dirname(__FILE__) + '/api/readme_api'

run CalculatorService::CalculatorApi.new
rchampourlier commented 11 years ago

Thanks for the details, it helps to solve the problem!

The issue is just that in your config guard-shotgun is not watching your config.ru file, it will only reload when something you mark as watched is changed.

Make this your guard-shotgun config and your issue is gone:

guard 'shotgun', :server => 'thin' do
  watch %r{^(app|lib|config)/.*\.rb}
  watch 'config.ru'
end

I'll however update the README to include this. Thanks!