zakird / wkhtmltopdf_binary_gem

Ruby gem containing easily installable access to wkhtmltopdf application
https://rubygems.org/gems/wkhtmltopdf-binary
Apache License 2.0
184 stars 346 forks source link

Bundler Error during Deployment - undefined method `size' for nil:NilClass in wkhtmltopdf-binary gem #166

Open muhammadawais05 opened 1 year ago

muhammadawais05 commented 1 year ago

Issue Summary: I encountered an issue while deploying a Rails application using Capistrano. The deployment process fails during the bundler:install task with the following error:

Exception while verifying /path/to/bundle/cache/wkhtmltopdf-binary-0.12.6.6.gem NoMethodError: undefined method `size' for nil:NilClass @read += ret.size

Environment:

Ruby version: 3.1.2 Bundler version: 2.4.22

Steps to Reproduce:

Clone the repository. Run cap production deploy to deploy the Rails application. Expected Behavior: The deployment process should complete successfully without errors.

Actual Behavior: The deployment fails with the mentioned error related to the wkhtmltopdf-binary gem.

Additional Information:

Gemfile content:

source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.1.2"

# Use Sass to process CSS
gem "sassc-rails"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.8"

gem 'activeadmin'
gem 'devise'
gem 'pundit'

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use postgresql as the database for Active Record
gem "pg", "~> 1.1"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 4.0"

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

gem 'wkhtmltopdf-binary', '~> 0.12.6.6'
gem 'wicked_pdf'

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
gem "image_processing", '>= 1.2'

group :development do
  gem "debug", platforms: %i[ mri mingw x64_mingw ]
  # Use console on exceptions pages [https://github.com/rails/web-console]
  gem "web-console"

  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
  # gem "rack-mini-profiler"

  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"
  gem 'rvm1-capistrano3', require: false
  gem 'capistrano-bundler', require: false
  gem "capistrano", "~> 3.10", require: false
  gem "capistrano-rails", "~> 1.6", require: false
end

group :test do
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"
end

Possible Solutions (if any): I have tried different possible solutions found on Google but they did not work.

References:

Note: This issue seems to be specific to the wkhtmltopdf-binary gem during the deployment process. I have checked for existing reports on the RubyGems GitHub repository, and no similar issues were found. I'm creating this issue to seek assistance in resolving the problem.

![Uploading Screenshot 2023-11-17 at 11.56.36 PM.png…]() ![Uploading Screenshot 2023-11-17 at 11.58.08 PM.png…]()

unixmonkey commented 1 year ago

That error isn't coming from this gem, it's coming from Rubygems' bundler at this line, where it is trying to unpack the gem file that was downloaded.

It seems to me that the file didn't download successfully, even though the system thought it did.

I would try and re-deploy. It might have been an intermittent issue downloading from the rubygems servers.

If it continues to fail, then it might be something with your deployment setup. One thing that is fairly unique about this gem, is that it is quite large, as far as Ruby gems go. It's about 261MB. Maybe your system doesn't have enough drive space to save it to disk, enough tmp space or memory to unpack it?

Another thing you might consider is just pulling out the single wkhtmltopdf binary you need and deploying it vendored in with your code, or by creating an OS-specific internal gem.

Please let me know how it goes, and how you solved your issue!

muhammadawais05 commented 1 year ago

That error isn't coming from this gem, it's coming from Rubygems' bundler at this line, where it is trying to unpack the gem file that was downloaded.

It seems to me that the file didn't download successfully, even though the system thought it did.

I would try and re-deploy. It might have been an intermittent issue downloading from the rubygems servers.

If it continues to fail, then it might be something with your deployment setup. One thing that is fairly unique about this gem, is that it is quite large, as far as Ruby gems go. It's about 261MB. Maybe your system doesn't have enough drive space to save it to disk, enough tmp space or memory to unpack it?

Another thing you might consider is just pulling out the single wkhtmltopdf binary you need and deploying it vendored in with your code, or by creating an OS-specific internal gem.

Please let me know how it goes, and how you solved your issue!

There is an enough space on the server. So I think it is not because of the space. Secondly, one thing I have noticed is when I remove gem 'wkhtmltopdf-binary', '~> 0.12.6.6' from the gem file then deploy the code on production. It deploys on the server.

error on bundler:install on executing cap production deploy when gem 'wkhtmltopdf-binary', '~> 0.12.6.6' is included in the gemfile:

01:58 bundler:install 01 /home/deployer/www/medicolegalreport/rvm1scripts/rvm-auto.sh ruby-3.1.2 bundle install --jobs 4 --quiet 01 Exception while verifying /home/deployer/www/medicolegalreport/shared/bundle/ruby/3.1.0/cache/wkhtmltopdf-binary-0.12.6.6.gem 01 --- ERROR REPORT TEMPLATE ------------------------------------------------------- 01 01 ``` 01 NoMethodError: undefined methodsize' for nil:NilClass 01 01 @read += ret.size 01 ^^^^^ 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package/tar_reader/entry.rb:139:in read' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package.rb:364:inblock in digest' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package.rb:361:in each' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package.rb:361:indigest' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package.rb:647:in verify_entry' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package.rb:666:inblock in verify_files' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package/tar_reader.rb:65:in each' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package.rb:665:inverify_files' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package.rb:596:in block (2 levels) in verify' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package/tar_reader.rb:27:innew' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package.rb:593:in block in verify' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package/file_source.rb:29:inopen' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package/file_source.rb:29:in with_read_io' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package.rb:592:inverify' 01 /usr/local/rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/package.rb:573:in spec' 01 /home/deployer/www/medicolegalreport/shared/bundle/ruby/3.1.0/gems/bundler-2.4.16/lib/bundler/rubygems_gem_installer.rb:95:inspec' 01 /home/deployer/www/medicolegalreport/shared/bundle/ruby/3.1.0/gems/bundler-2.4.16/lib/bundler/source/rubygems.rb:185:in install' 01 /home/deployer/www/medicolegalreport/shared/bundle/ruby/3.1.0/gems/bundler-2.4.16/lib/bundler/installer/gem_installer.rb:54:ininstall' 01 /home/deployer/www/medicolegalreport/shared/bundle/ruby/3.1.0/gems/bundler-2.4.16/lib/bundler/installer/gem_installer.rb:16:in install_from_spec' 01 /home/deployer/www/medicolegalreport/shared/bundle/ruby/3.1.0/gems/bundler-2.4.16/lib/bundler/installer/parallel_installer.rb:156:indo_install' 01 /home/deployer/www/medicolegalreport/shared/bundle/ruby/3.1.0/gems/bundler-2.4.16/lib/bundler/installer/parallel_installer.rb:147:in block in worker_pool' 01 /home/deployer/www/medicolegalreport/shared/bundle/ruby/3.1.0/gems/bundler-2.4.16/lib/bundler/worker.rb:62:inapply_func' 01 /home/deployer/www/medicolegalreport/shared/bundle/ruby/3.1.0/gems/bundler-2.4.16/lib/bundler/worker.rb:57:in block in process_queue' 01 /home/deployer/www/medicolegalreport/shared/bundle/ruby/3.1.0/gems/bundler-2.4.16/lib/bundler/worker.rb:54:inloop' 01 /home/deployer/www/medicolegalreport/shared/bundle/ruby/3.1.0/gems/bundler-2.4.16/lib/bundler/worker.rb:54:in process_queue' 01 /home/deployer/www/medicolegalreport/shared/bundle/ruby/3.1.0/gems/bundler-2.4.16/lib/bundler/worker.rb:90:inblock (2 levels) in create_threads' 01 01 01 01 ## Environment 01 01 `

` DEPLOY FAILED Refer to log/capistrano.log for details. Here are the last 20 lines:

tzinfo-data

web-console

wicked_pdf

wkhtmltopdf-binary (~> 0.12.6.6)

RUBY VERSION

ruby 3.1.2p20

BUNDLED WITH

2.4.16



--- TEMPLATE END ----------------------------------------------------------------

 DEBUG [1f6883a7]   Unfortunately, an unexpected error occurred, and Bundler cannot continue.

 DEBUG [1f6883a7]   

First, try this link to see if there are any existing issue reports for this error:

https://github.com/rubygems/rubygems/search?q=undefined+method+%60size%27+for+nil+NilClass&type=Issues`
unixmonkey commented 1 year ago

Try running bundle pristine wkhtmltopdf-binary on the server, or gem uninstall wkhtmltopdf-binary. Either one should remove any left behind or corrupted files that might be on the system. Then try and bundle install again.

Even if you have enough disk space, I’ve heard of issues with quotas on temporary space, or timeouts during deploy.

again, you can also browse the bin dir of this project and just grab the binary for your OS, which is probably only 20mb or so. This gem has a lot of binaries for many different OS’s.