guard / listen

The Listen gem listens to file modifications and notifies you about the changes.
https://rubygems.org/gems/listen
MIT License
1.92k stars 245 forks source link

listener.stop fails with undefined method `alive?' for nil:NilClass if called before started #513

Closed ColinDKelley closed 3 years ago

ColinDKelley commented 3 years ago

Current State

If a listener hasn't been started yet, a call to stop will raise an exception:

listener = Listen.to(path) do { ... }
listener.stop
NoMethodError:
       undefined method `alive?' for nil:NilClass
     # /usr/local/bundle/gems/listen-3.3.0/lib/listen/event/loop.rb:70:in `stop'
     # /usr/local/bundle/gems/listen-3.3.0/lib/listen/listener.rb:82:in `block in <class:Listener>'
     # /usr/local/bundle/gems/listen-3.3.0/lib/listen/fsm.rb:121:in `instance_eval'
     # /usr/local/bundle/gems/listen-3.3.0/lib/listen/fsm.rb:121:in `call'
     # /usr/local/bundle/gems/listen-3.3.0/lib/listen/fsm.rb:102:in `transition_with_callbacks!'
     # /usr/local/bundle/gems/listen-3.3.0/lib/listen/fsm.rb:69:in `transition'
     # /usr/local/bundle/gems/listen-3.3.0/lib/listen/listener.rb:101:in `stop'

Desired State

The stop method should always succeed--even when not started.

Steps to Reproduce

Call stop before starting:

listener = Listen.to(path) do { ... }
listener.stop
ColinDKelley commented 3 years ago

Fixed by https://github.com/guard/listen/pull/514