Skip to content

Commit

Permalink
Fix uncaught LoadError requiring pygments.rb
Browse files Browse the repository at this point in the history
If `ghi` was installed via Homebrew before pygments.rb was added as a
dependency, the check for pygments being installed never gets run. It
looks like there was intention to rescue that `require` statement but
because `LoadError` doesn't inherit from `StandardError`, the exception
was uncaught and `ghi` would silently exit. This only seems to happen
currently on issues that include fenced code blocks, but I provided
reproducible evidence in stephencelis#281. Merging this will fix stephencelis#281, but I have
two concerns about the fact that pygments.rb was included as a
dependency in the first place:

1. Homebrew doesn't install Ruby gems for you, so this has to be done
   manually. Attempting to `brew install ghi` without first having run
   `gem install pygments.rb` just outputs an error and doesn't finish.
2. Most Ruby developers install several versions of Ruby using a version
   manager like rvm, rbenv, or chruby. You can `gem install pygments.rb`
   on one version of Ruby (or `sudo gem install pygments.rb` on the
   system version of Ruby, which is a whole other problem) but as soon
   as you try to use `ghi` after switching Rubies, you have to remember
   to install `pygments.rb`. This isn't great.

I see two solutions here. We can either no longer offer a Homebrew
formula, instead urging users to just install via `gem install ghi` or
we can remove pygments.rb as a dependency. Personally I think `ghi`
should try to remain free of dependencies for this reason, but I leave
it in your hands.

Signed-off-by: David Celis <me@davidcel.is>
  • Loading branch information
davidcelis committed Apr 8, 2016
1 parent 01ac0ce commit 084185a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ghi
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ module GHI
raise unless supports_256_colors?
require 'pygments'
Pygmentizer.new
rescue
rescue StandardError, LoadError
FakePygmentizer.new
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ghi/formatting/colors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def highlighter
raise unless supports_256_colors?
require 'pygments'
Pygmentizer.new
rescue
rescue StandardError, LoadError
FakePygmentizer.new
end
end
Expand Down

0 comments on commit 084185a

Please sign in to comment.