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

NoMethodError #82

Closed
rajeevramani opened this Issue Apr 5, 2011 · 10 comments

Comments

Projects
None yet
8 participants
@rajeevramani

rajeevramani commented Apr 5, 2011

NoMethodError (undefined method `chomp' for nil:NilClass):

I am getting this error.

I am using rails 3.0.3.

I completed all the setup including installation of wkhtmltopdf. I dont see any other error expect what I have listed here.

@mdeering

This comment has been minimized.

Show comment
Hide comment
@mdeering

mdeering May 10, 2011

Member

Not enough information to pin this on PDFKit. Is there any type of backtrace that you can add as a Gist? Closing this issue. Please reopen if you are still having problems with the appropriate information.

Member

mdeering commented May 10, 2011

Not enough information to pin this on PDFKit. Is there any type of backtrace that you can add as a Gist? Closing this issue. Please reopen if you are still having problems with the appropriate information.

@mdeering mdeering closed this May 10, 2011

@nicholaides

This comment has been minimized.

Show comment
Hide comment
@nicholaides

nicholaides Sep 12, 2011

I'm having this issue, too.

Weird thing is, the logs don't show a backtrace, only:

NoMethodError (undefined method `chomp' for nil:NilClass):

Also, it happens after the request:

Started GET "/export/download.pdf?start_date=02%2F01%2F2011&end_date=09%2F12%2F2011&commit=Export" for [redacted] at 2011-09-12 15:49:54 +0000
  Processing by ExportsController#download as HTML
  Parameters: {"start_date"=>"02/01/2011", "end_date"=>"09/12/2011", "commit"=>"Export"}
Rendered exports/download.html.haml (4.8ms)
Completed 200 OK in 137ms (Views: 5.6ms)

NoMethodError (undefined method `chomp' for nil:NilClass):

Furthermore the error isn't sent to Airbrake (prev. Hoptoad).

When I remove the .pdf from the url, it gives me the HTML page as expected. Also, I can use PDFKit from the console just fine.

I suspect it's an issue with the middleware. Could it be an issue with other middleware I'm using? With Passenger?

nicholaides commented Sep 12, 2011

I'm having this issue, too.

Weird thing is, the logs don't show a backtrace, only:

NoMethodError (undefined method `chomp' for nil:NilClass):

Also, it happens after the request:

Started GET "/export/download.pdf?start_date=02%2F01%2F2011&end_date=09%2F12%2F2011&commit=Export" for [redacted] at 2011-09-12 15:49:54 +0000
  Processing by ExportsController#download as HTML
  Parameters: {"start_date"=>"02/01/2011", "end_date"=>"09/12/2011", "commit"=>"Export"}
Rendered exports/download.html.haml (4.8ms)
Completed 200 OK in 137ms (Views: 5.6ms)

NoMethodError (undefined method `chomp' for nil:NilClass):

Furthermore the error isn't sent to Airbrake (prev. Hoptoad).

When I remove the .pdf from the url, it gives me the HTML page as expected. Also, I can use PDFKit from the console just fine.

I suspect it's an issue with the middleware. Could it be an issue with other middleware I'm using? With Passenger?

@nicholaides

This comment has been minimized.

Show comment
Hide comment
@nicholaides

nicholaides Sep 12, 2011

Ok, here's the backtrace (I turned off Rails' backtrace silencers):

NoMethodError (undefined method `chomp' for nil:NilClass):
  pdfkit (0.5.2) lib/pdfkit/configuration.rb:20:in `wkhtmltopdf'
  pdfkit (0.5.2) lib/pdfkit/pdfkit.rb:29:in `initialize'
  pdfkit (0.5.2) lib/pdfkit/middleware.rb:21:in `new'
  pdfkit (0.5.2) lib/pdfkit/middleware.rb:21:in `call'
  sass (3.1.7) lib/sass/plugin/rack.rb:54:in `call'
  warden (1.0.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.0.3) lib/warden/manager.rb:34:in `catch'
  warden (1.0.3) lib/warden/manager.rb:34:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/head.rb:14:in `call'
  rack (1.2.3) lib/rack/methodoverride.rb:24:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/flash.rb:182:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/cookies.rb:302:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
  activesupport (3.0.10) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
  actionpack (3.0.10) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
  rack (1.2.3) lib/rack/sendfile.rb:107:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
  railties (3.0.10) lib/rails/rack/logger.rb:13:in `call'
  rack (1.2.3) lib/rack/runtime.rb:17:in `call'
  rack (1.2.3) lib/rack/lock.rb:11:in `block in call'
  <internal:prelude>:10:in `synchronize'
  rack (1.2.3) lib/rack/lock.rb:11:in `call'
  hoptoad_notifier (2.4.11) lib/hoptoad_notifier/user_informer.rb:12:in `call'
  railties (3.0.10) lib/rails/application.rb:168:in `call'
  railties (3.0.10) lib/rails/application.rb:77:in `method_missing'
  passenger (3.0.7) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
  passenger (3.0.7) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
  passenger (3.0.7) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
  passenger (3.0.7) lib/phusion_passenger/classic_rails/application_spawner.rb:321:in `start_request_handler'
  passenger (3.0.7) lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `block in handle_spawn_application'
  passenger (3.0.7) lib/phusion_passenger/utils.rb:479:in `safe_fork'
  passenger (3.0.7) lib/phusion_passenger/classic_rails/application_spawner.rb:270:in `handle_spawn_application'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:180:in `start'
  passenger (3.0.7) lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start'
  passenger (3.0.7) lib/phusion_passenger/spawn_manager.rb:219:in `block (2 levels) in spawn_rails_application'
  passenger (3.0.7) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
  passenger (3.0.7) lib/phusion_passenger/spawn_manager.rb:214:in `block in spawn_rails_application'
  passenger (3.0.7) lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
  <internal:prelude>:10:in `synchronize'
  passenger (3.0.7) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
  passenger (3.0.7) lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application'
  passenger (3.0.7) lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application'
  passenger (3.0.7) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  passenger (3.0.7) helper-scripts/passenger-spawn-server:99:in `<main>'

The problem is at lib/pdfkit/configuration.rb:20:

    def wkhtmltopdf
      @wkhtmltopdf ||= (defined?(Bundler::GemfileError) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp
    end

Apparently I don't have bundle in my path, even though Bundler::GemfileError is defined. bundle exec which wkhtmltopdf returns nil, which is causing this error.

My quick fix is to redefine the method in an initializer:

require 'pdfkit'
class PDFKit
  class Configuration
    def wkhtmltopdf
      @wkhtmltopdf ||= `which wkhtmltopdf`.chomp
    end
  end
end

nicholaides commented Sep 12, 2011

Ok, here's the backtrace (I turned off Rails' backtrace silencers):

NoMethodError (undefined method `chomp' for nil:NilClass):
  pdfkit (0.5.2) lib/pdfkit/configuration.rb:20:in `wkhtmltopdf'
  pdfkit (0.5.2) lib/pdfkit/pdfkit.rb:29:in `initialize'
  pdfkit (0.5.2) lib/pdfkit/middleware.rb:21:in `new'
  pdfkit (0.5.2) lib/pdfkit/middleware.rb:21:in `call'
  sass (3.1.7) lib/sass/plugin/rack.rb:54:in `call'
  warden (1.0.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.0.3) lib/warden/manager.rb:34:in `catch'
  warden (1.0.3) lib/warden/manager.rb:34:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/head.rb:14:in `call'
  rack (1.2.3) lib/rack/methodoverride.rb:24:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/flash.rb:182:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/cookies.rb:302:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
  activesupport (3.0.10) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
  actionpack (3.0.10) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
  rack (1.2.3) lib/rack/sendfile.rb:107:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
  actionpack (3.0.10) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
  railties (3.0.10) lib/rails/rack/logger.rb:13:in `call'
  rack (1.2.3) lib/rack/runtime.rb:17:in `call'
  rack (1.2.3) lib/rack/lock.rb:11:in `block in call'
  <internal:prelude>:10:in `synchronize'
  rack (1.2.3) lib/rack/lock.rb:11:in `call'
  hoptoad_notifier (2.4.11) lib/hoptoad_notifier/user_informer.rb:12:in `call'
  railties (3.0.10) lib/rails/application.rb:168:in `call'
  railties (3.0.10) lib/rails/application.rb:77:in `method_missing'
  passenger (3.0.7) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
  passenger (3.0.7) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
  passenger (3.0.7) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
  passenger (3.0.7) lib/phusion_passenger/classic_rails/application_spawner.rb:321:in `start_request_handler'
  passenger (3.0.7) lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `block in handle_spawn_application'
  passenger (3.0.7) lib/phusion_passenger/utils.rb:479:in `safe_fork'
  passenger (3.0.7) lib/phusion_passenger/classic_rails/application_spawner.rb:270:in `handle_spawn_application'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:180:in `start'
  passenger (3.0.7) lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start'
  passenger (3.0.7) lib/phusion_passenger/spawn_manager.rb:219:in `block (2 levels) in spawn_rails_application'
  passenger (3.0.7) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
  passenger (3.0.7) lib/phusion_passenger/spawn_manager.rb:214:in `block in spawn_rails_application'
  passenger (3.0.7) lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
  <internal:prelude>:10:in `synchronize'
  passenger (3.0.7) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
  passenger (3.0.7) lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application'
  passenger (3.0.7) lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application'
  passenger (3.0.7) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  passenger (3.0.7) helper-scripts/passenger-spawn-server:99:in `<main>'

The problem is at lib/pdfkit/configuration.rb:20:

    def wkhtmltopdf
      @wkhtmltopdf ||= (defined?(Bundler::GemfileError) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp
    end

Apparently I don't have bundle in my path, even though Bundler::GemfileError is defined. bundle exec which wkhtmltopdf returns nil, which is causing this error.

My quick fix is to redefine the method in an initializer:

require 'pdfkit'
class PDFKit
  class Configuration
    def wkhtmltopdf
      @wkhtmltopdf ||= `which wkhtmltopdf`.chomp
    end
  end
end
@ziemekwolski

This comment has been minimized.

Show comment
Hide comment
@ziemekwolski

ziemekwolski Jun 2, 2014

I just want to Thanks for finding and posting a work around!

ziemekwolski commented Jun 2, 2014

I just want to Thanks for finding and posting a work around!

@paulkoegel

This comment has been minimized.

Show comment
Hide comment
@paulkoegel

paulkoegel Dec 2, 2015

saved my day - even though bundle exec ... returned the proper path both on the command line and in the rails console!?

paulkoegel commented Dec 2, 2015

saved my day - even though bundle exec ... returned the proper path both on the command line and in the rails console!?

@cdwort

This comment has been minimized.

Show comment
Hide comment
@cdwort

cdwort Dec 2, 2015

Contributor

@paulkogel Is this happening on a recent version of PDFKit? Mind posting your version?

Contributor

cdwort commented Dec 2, 2015

@paulkogel Is this happening on a recent version of PDFKit? Mind posting your version?

@paulkoegel

This comment has been minimized.

Show comment
Hide comment
@paulkoegel

paulkoegel Dec 3, 2015

I'm using pdfkit (0.8.2) and wkhtmltopdf-binary (0.9.9.3)

paulkoegel commented Dec 3, 2015

I'm using pdfkit (0.8.2) and wkhtmltopdf-binary (0.9.9.3)

@gurunathsane

This comment has been minimized.

Show comment
Hide comment
@gurunathsane

gurunathsane Jul 20, 2016

yes 'which wkhtmltopdf' returned a path but I am still facing the same issue

gurunathsane commented Jul 20, 2016

yes 'which wkhtmltopdf' returned a path but I am still facing the same issue

@gurunathsane

This comment has been minimized.

Show comment
Hide comment
@gurunathsane

gurunathsane Aug 8, 2016

can we add custom path in config files instead direct change in Gems files

gurunathsane commented Aug 8, 2016

can we add custom path in config files instead direct change in Gems files

@sigmavirus24

This comment has been minimized.

Show comment
Hide comment
@sigmavirus24

sigmavirus24 Aug 8, 2016

Contributor

I'll post the link to the configuration documentation and lock this issue.

Contributor

sigmavirus24 commented Aug 8, 2016

I'll post the link to the configuration documentation and lock this issue.

@pdfkit pdfkit locked and limited conversation to collaborators Aug 8, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.