Skip to content

Commit

Permalink
Ignore Bundler 1.14.* warning messages on a non-writable home directory
Browse files Browse the repository at this point in the history
In Bundler 1.14, there was a [merged pull request](rubygems/bundler#4951) that introduced new functionality. When running `bundle` if the location specified in `Bundler.rubygems.user_home` has a problem (e.g. does not exist, is not writable, is not a directory), it prints out a warning message to STDOUT.

You can see an example by running in bash:

```
gem install bundler --version 1.14.3
echo "source 'https://rubygems.org';\ngem 'wkhtmltopdf-binary-edge'" > Gemfile
bundle install --path vendor/bundle

HOME=/no/directory/found bundle exec which wkhtmltopdf
```

When run, you can see the output looks something like:

```
Your home directory is not set properly:
 * `/no/directory/found` is not a directory

Bundler will use `/var/folders/wj/q7cqmwds75z3ndcdxrmpd9gh0000gn/T/bundler/home/rdimarco` as your home directory temporarily
```

The problem is that the [output from `bundle exec which wkhtmltopdf`] (https://github.com/pdfkit/pdfkit/blob/master/lib/pdfkit/configuration.rb#L26) is used to determine the path to the default `wkhtmltopdf` executable.

So since there is the warning included in the output, the executable path contains the warning messages and is not valid.

This commit will look at the lines returned by the `witch` statement and will return the first file path that it finds, ignoring the warning messages.
  • Loading branch information
Rob Di Marco committed Feb 3, 2017
1 parent 36da50b commit 0f4d444
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/pdfkit/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ def wkhtmltopdf
end

def default_wkhtmltopdf
@default_command_path ||= (defined?(Bundler::GemfileError) && File.exists?('Gemfile') ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp
@default_command_path ||=
if defined?(Bundler::GemfileError) && File.exists?('Gemfile')
# Starting with Bundler 1.14, if the Bundler.rubygems.user_home value
# is a read-only or non-existent directory, Bundler prints out an error message.
# We want to ignore this message, so we want to find the first line that points
# to a file
`bundle exec which wkhtmltopdf`.lines.detect { |l| File.file?(l) }.to_s.chomp
else
`which wkhtmltopdf`.chomp
end
end

def wkhtmltopdf=(path)
Expand Down

0 comments on commit 0f4d444

Please sign in to comment.