mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.54k stars 646 forks source link

Wicked PDF does not respect gemsets #340

Open apolzon opened 10 years ago

apolzon commented 10 years ago

When Wicked PDF attempts to find the wkhtmltopdf binary path, it attempts to shell out to bundle exec to determine the location of the wkhtmltopdf binary. However, this will execute bundle exec in a new shell which will use a global gemset, triggering a bundler error as many gems will likely not be installed.

ie:

/Users/apolzon/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.6.1/lib/bundler/source/git.rb:187:in `rescue in load_spec_files': git://github.com/brandmart/paperclip.git (at master) is not yet checked out. Run `bundle install` first. (Bundler::GitError)

I'm not sure what the correct way to handle this is, but it might be worth adding a note to the Readme regarding this issue.

julienfromentc commented 9 years ago

I also encountered this issue

+1

andrew-agape commented 9 years ago

I'm seeing the same issue and it cropped up unexpectedly. One minute it worked great and continues to work in staging. In the local Ubuntu image where it was working it's erroring out even after reverting the code, restarting the box, restarting the server.

In my case it was throwing this error: "git://github.com/nixme/jazz_hands.git (at bring-your-own-debugger) is not yet checked out. Run bundle install first."

Commenting that Gem out and bundling made the error go away.

andrew-carroll commented 9 years ago

Having this issue as well.

Ruby 2.1.2 Rails 4.1.0

Offending lines in Gemfile:

gem 'figaro', github: "laserlemon/figaro" gem 'Indirizzo', git: 'https://github.com/daveworth/Indirizzo.git'

Commenting out either of them, or even just their git components, fixes the problem.

edit:

***************WICKED***************
  Rendered searches/search.pdf.haml (4.9ms)
"***************[\"/home/andrew/.rvm/gems/ruby-2.1.2/bin/wkhtmltopdf\", \"-q\", \"file:///tmp/wicked_pdf20150101-3960-1iptntr.html\", \"/tmp/wicked_pdf_generated_file20150101-3960-zncuxz.pdf\"]***************"
Completed 500 Internal Server Error in 1027ms

RuntimeError (Error: Failed to execute:
["/home/andrew/.rvm/gems/ruby-2.1.2/bin/wkhtmltopdf", "-q", "file:///tmp/wicked_pdf20150101-3960-1iptntr.html", "/tmp/wicked_pdf_generated_file20150101-3960-zncuxz.pdf"]
Error: PDF could not be generated!
 Command Error: /home/andrew/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.7/lib/bundler/source/git.rb:188:in `rescue in load_spec_files': https://github.com/daveworth/Indirizzo.git (at master) is not yet checked out. Run `bundle install` first. (Bundler::GitError)
    from /home/andrew/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.7.7/lib/bundler/source/git.rb:185:in `load_spec_files'
unixmonkey commented 9 years ago

If you specify the path to your binary manually in config/initializers/wicked_pdf.rb using your own path to the binary as shown here: https://github.com/mileszs/wicked_pdf#installation

Then you'll bypass the bundle exec wkhtmltopdf part and it will just run wkhtmltopdf with the options it needs.

showaltb commented 9 years ago

This is what I am doing to address this:

tagliala commented 9 years ago

If you specify the path to your binary manually in config/initializers/wicked_pdf.rb using your own path to the binary as shown here: https://github.com/mileszs/wicked_pdf#installation

Then you'll bypass the bundle exec wkhtmltopdf part and it will just run wkhtmltopdf with the options it needs.

Doesn't work for me.

Error before: Location of wkhtmltopdf unknown because of the exception in bundle exec, so that find_wkhtmltopdf_binary_path returns nil

Error after: Error: Failed to execute: path/to/wkhtmltopdf. Same reason as above is not yet checked out....

tagliala commented 9 years ago

This is what I am doing to address this:

(Optional) run gem install wkhtmtopdf-binary in global gemset Add gem 'wkthmltopdf-binary' to Gemfile Run bundle binstubs wkhtmltopdf-binary, which generates bin/wkhtmltopdf Set wkhtmltopdf: File.join(Rails.root, 'bin/wkhtmltopdf') in config/initializers/wicked_pdf.rb

Didn't work too. Looking for another solution

Rails 4.2.0 Ruby 2.1.5 OSX 10.10.2 rvm 1.26.10

tagliala commented 9 years ago

It is caused by spring, I suppose, offending line:

https://github.com/rails/spring/blob/666db7ddbdf990f9ef03cc52c872c4e402cc543d/lib/spring/client/binstub.rb#L41

bin/spring.rb

#!/usr/bin/env ruby

# This file loads spring without using Bundler, in order to be fast
# It gets overwritten when you run the `spring binstub` command

unless defined?(Spring)
  require "rubygems"
  require "bundler"

  if match = Bundler.default_lockfile.read.match(/^GEM$.*?^    (?:  )*spring \((.*?)\)$.*?^$/m)
    ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
    ENV["GEM_HOME"] = "" # <-- this is causing the issue
    Gem.paths = ENV

    gem "spring", match[1]
    require "spring/binstub"
  end
end
klochner commented 9 years ago

confirmed spring is the issue. If you're running on a fast machine I would just remove spring, it causes way more headaches than benefits.

boxofrox commented 9 years ago

I just ran into this error...

(at master) is not yet checked out. Run `bundle install` first. (Bundler::GitError)`)

...using a github repo to supply the wkhtmlpdf binaries.

After dumping a bunch of STDERR.puts in my bundler gem, I found Bundler's source/git.rb was using my project folder as the gem install path instead of rvm's. Thanks to this issue, I considered spring as the culprit and visited their github page where they recommend running...

bundle exec spring binstub --all

which fixed this error for me. YMMV since I'm only dealing with a github gem full of binaries instead of paperclip and the like. Cheers.