seattlerb / debride

Analyze code for potentially uncalled / dead methods, now with auto-removal.

Home Page:https://www.zenspider.com/projects/debride.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failure to load plugins raises confusing exception

phiggins opened this issue · comments

Debride.load_plugins currently swallows exceptions and returns nil, when the caller Debride.file_extensions is expecting an array. This makes file_extensions raise an exception because it is trying to do %w[rake rb] + nil and fails.

I can think of a few ways to solve this but I wanted to get your opinion before I attempted any fixes:

  1. Don't swallow exceptions in load_plugins and just let it crash.
  2. Continue swallowing exceptions in load_plugins but make the rescue block at the end return an empty array or @@plugins.
  3. Have file_extensions coerce the return value of load_plugins into an array by using Array or something.

In case you're curious what led to this: something was busted in my local setup. I run debride on $dayjob's big old rails app but I don't add debride to the Gemfile to avoid throwing more fuel on that fire. Debride worked if I put it in the Gemfile and ran bundle, but not if I left it out of the Gemfile and installed it with gem install. It turns out I was running into this exception and updating to the latest version of rubygems made it work again: rubygems/rubygems#1420

BTW I think I prefer solution 1 because it would have helped me debug the problem faster. WDYT?

You want to swallow exceptions so plugins can try to require dependencies and fail.

OK. I fixed the inner rescue to get RuntimeError as well as LoadError so now they'll report that they had a problem and move on cleanly. Top level rescue is probably not necessary now, but I made it return an empty array.

Cool, thank you!