Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only grab last line of bundle exec which output #464

Merged
merged 2 commits into from Jul 6, 2020
Merged

Only grab last line of bundle exec which output #464

merged 2 commits into from Jul 6, 2020

Conversation

maneyko
Copy link
Contributor

@maneyko maneyko commented Apr 1, 2020

When running pdfkit in a docker container for our configuration, there is no home directory. Bundler < 2 has a warning for this and it goes to STDOUT (see: rubygems/bundler#6067). Here is the example:

irb(main):001:0> `bundle exec which wkhtmltopdf`.chomp
=> "`/home/myuser` is not a directory.\nBundler will use `/tmp/bundler/home/myuser' as your home directory temporarily.\n/usr/bin/wkhtmltopdf"
irb(main):002:0> `bundle exec which wkhtmltopdf`.chomp.lines.last
=> "/usr/bin/wkhtmltopdf"

Now an example where the warning does not come up:

2.4.6 :001 > `bundle exec which wkhtmltopdf`.chomp
 => "/usr/local/bin/wkhtmltopdf"
2.4.6 :002 > `bundle exec which wkhtmltopdf`.chomp.lines.last
 => "/usr/local/bin/wkhtmltopdf"

This PR seems to be very similar to the recently merged #460

Looking forward to your feedback.

@maneyko
Copy link
Contributor Author

maneyko commented Apr 29, 2020

In the above example, if

irb(main):001:0> @default_command_path = `bundle exec which wkhtmltopdf`.chomp
=> "`/home/myuser` is not a directory.\nBundler will use `/tmp/bundler/home/myuser' as your home directory temporarily.\n/usr/bin/wkhtmltopdf"

Then @default_command_path will remain unchanged after lib/pdfkit/configuration.rb#L32 since it is not nil and not empty. This results in unexpected behavior as @default_command_path is a multiline string with warning messages. As a result, the wkhtmltopdf executable cannot be found by pdfkit, as this error comes up elsewhere downstream, even though it just needs to be parsed from this output more accurately.

Based on the context here, it seems that there is never a scenario where we would want multiline output from bundle exec which wkhtmltopdf, so if anything it adds as a safeguard against these kinds of situations.

Copy link
Contributor

@serene serene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test for this?

@maneyko
Copy link
Contributor Author

maneyko commented Jun 11, 2020

@serene
Done. Thanks.

@serene serene added the ready label Jun 11, 2020
@serene serene merged commit bbaac04 into pdfkit:master Jul 6, 2020
@maneyko maneyko deleted the path-detection-last-line branch July 6, 2020 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants