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

NoMethodError: undefined method `read' for nil:NilClass when calling du.recreate_versions!(:some_version) #2186

Closed
fatuhoku opened this issue May 30, 2017 · 7 comments
Labels

Comments

@fatuhoku
Copy link

fatuhoku commented May 30, 2017

Carrierwave version: 1.1.0. Code:

# document_image_uploader.rb

   ...
  version :some_version, if: :image? do
    process :resize_to_fit => [2048, 2048]
  end

  # See http://stackoverflow.com/a/30897174/590767
  def image?(new_file)
    new_file.content_type.start_with? 'image'
  end

In the console:

> du = DocumentImageUploader.new # this is a CarrierWave::Uploader::Base subclass
> du.recreate_versions!(:some_version)
NoMethodError: undefined method `read' for nil:NilClass
	from ~/.rvm/gems/ruby-2.2.7/gems/carrierwave-1.1.0/lib/carrierwave/uploader/cache.rb:81:in `sanitized_file'
	from ~/.rvm/gems/ruby-2.2.7/gems/carrierwave-1.1.0/lib/carrierwave/uploader/versions.rb:224:in `recreate_versions!'
	from (irb):5
	from ~/.rvm/gems/ruby-2.2.7/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in `start'
	from ~/.rvm/gems/ruby-2.2.7/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
	from ~/.rvm/gems/ruby-2.2.7/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
	from ~/.rvm/gems/ruby-2.2.7/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
	from ~/.rvm/gems/ruby-2.2.7/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
	from bin/rails:8:in `require'
	from bin/rails:8:in `<main>'
@fatuhoku
Copy link
Author

Pretty stumped. Now I must find another way to recreate all the versions :S

@pipo24
Copy link

pipo24 commented May 30, 2017

@fatuhoku yeah this is quite annoying

@fatuhoku
Copy link
Author

I found that this does work for some images and not for others. Guess I can skip over them?

# Find out the offending models...
Model.all.each{|m|m.try(:image).try(:recreate_versions!) rescue (puts m.id) }

@fatuhoku
Copy link
Author

Found out that the document uploader exists but the size of the file stored is zero. Not sure why.

@scottbullard
Copy link

Anecdotally, I found that our recreate_versions! issue was because the file dimensions were too big. We've implemented carrierwave-bombshelter & carrierwave-imageoptimizer.

When the image exceeds 4096x4096 on some particular images we receive the:

NoMethodError: undefined method read' for nil:NilClass`

Other times we receive the appropriate bombshelter error:

CarrierWave::IntegrityError Image size should be less than or equal to 4096x4096

I'm not sure why the read error is shown on some images while the integrity error is shown on others. If I re-crop images to be below 4096x4096 the image versions are processed without issue.

Sample code:

class BannerUploader < CarrierWave::Uploader::Base
  include CarrierWave::BombShelter
  include CarrierWave::MiniMagick
  include CarrierWave::ImageOptimizer
  process :optimize

  ...
  # uploader details
end

Worker: due to direct-to-S3 uploads, we utilize the remote_#{column}_url method.

class BannerWorker
  def self.perform(obj_id, key)
    # object info...
    obj.remote_banner_url = "https://s3-bucket/#{key}"
    obj.banner.recreate_versions!
  end
end

@mshibuya
Copy link
Member

mshibuya commented May 1, 2019

#1879 have fixed this issue, I guess.

@mshibuya mshibuya closed this as completed May 1, 2019
@pepetorres1998
Copy link

I have bundled carrierwave from master (2.0.0.alpha) and stills give me the same error.

NoMethodError: undefined method read' for nil:NilClass`

After running @fatuhoku code: Model.all.each{|m|m.try(:image).try(:recreate_versions!) rescue (puts m.id) }, it seems that the error is caused by nil pictures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants