guard / listen

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

Getting ERROR -- : Exception rescued in _process_changes: on an exception raise in the block #547

Open github0013 opened 2 years ago

github0013 commented 2 years ago

I checked the issues, and I found this https://github.com/guard/listen/pull/535 . It should be the same error?

Environments

Reproduction

Let this run.

Loading development environment (Rails 5.2.6)
[1] pry(main)> begin
  listener = Listen.to("/app") do |modified, added, removed|
    raise if added.size > 0
  end
  listener.start
  sleep
rescue => ex
  puts "rescued #{ex.message}"
ensure
  listener.stop
end

Then touch a file.

$ touch /app/file

And I get this in the console.

E, [2021-09-10T12:59:43.731341 #386] ERROR -- : Exception rescued in _process_changes:
RuntimeError:
(pry):3:in `block in <main>'
/usr/local/bundle/gems/listen-3.7.0/lib/listen/event/config.rb:28:in `call'
/usr/local/bundle/gems/listen-3.7.0/lib/listen/event/processor.rb:117:in `block in _process_changes'
/usr/local/bundle/gems/listen-3.7.0/lib/listen/thread.rb:26:in `rescue_and_log'
/usr/local/bundle/gems/listen-3.7.0/lib/listen/event/processor.rb:116:in `_process_changes'
/usr/local/bundle/gems/listen-3.7.0/lib/listen/event/processor.rb:25:in `block in loop_for'
/usr/local/bundle/gems/listen-3.7.0/lib/listen/event/processor.rb:20:in `loop'
/usr/local/bundle/gems/listen-3.7.0/lib/listen/event/processor.rb:20:in `loop_for'
/usr/local/bundle/gems/listen-3.7.0/lib/listen/event/loop.rb:85:in `_process_changes'
/usr/local/bundle/gems/listen-3.7.0/lib/listen/event/loop.rb:51:in `block in start'
/usr/local/bundle/gems/listen-3.7.0/lib/listen/thread.rb:26:in `rescue_and_log'
/usr/local/bundle/gems/listen-3.7.0/lib/listen/thread.rb:18:in `block in new'

I need to catch the exception the listen block raises, so I can safely stop the main thread, but it seems the runtime error is not rescuable as above. (not going through puts "rescued #{ex.message}" part)

I tried this https://github.com/guard/listen/issues/362#issuecomment-170323804 Thread.main.wakeup but it's only good when the main thread is sleeping. (if it's blocking by file access or whatnot, it doesn't work)

ColinDKelley commented 2 years ago

One idea I'm considering is to make listen work optionally with the escalate gem. That gem provides a hook for escalating exceptions. I wouldn't want to have a hard dependency, but perhaps if it's been required by the time the listen code is running, it could use that hook.

@github0013 What do you think? If you could register an escalate callback to intercept these exceptions, would that do what you need?

ColinDKelley commented 2 years ago

@github0013 Any opinion here?

ColinDKelley commented 2 years ago

@github0013 Just checking in here. Any opinions above? Is this ticket is worth keeping open?

github0013 commented 2 years ago

@ColinDKelley

Sory I had been on a busy project, and I couldn't come back to github at all. Let me look into escalate gem and get back to you.

ColinDKelley commented 2 years ago

@github0013 Ok, thanks. And no pressure to use that gem! I'm open to any alternatives.