group:developmentdogem'pry-rails'# use pry when running `rails console`gem'pry-byebug'endgem'carrierwave',path:'../carrierwave'
The next thing I did was take a look at the CarrierWave source and made an educated guess at where the problem might be occurring. I added binding.pry to invoke Pry; (a Pry shell will fire up inside your Rails server log)
From:/Users/benwoodward/dev/carrierwave/lib/carrierwave/uploader/download.rb@line73CarrierWave::Uploader::Download#download!:68:defdownload!(uri)69:processed_uri=process_uri(uri)70:file=RemoteFile.new(processed_uri)71:raiseCarrierWave::DownloadError,"trying to download a file which is not served over HTTP"unlessfile.http?72:binding.pry=>73:cache!(file)74:end
The root of the problem is revealed
Using the next command provided by pry-byebug, I walked my way through the call stack until I discovered the root of the problem. (Walking through the stack like this is a great way to learn about how a Gem works in my opinion).
pry(#<CompanyLogoUploader>)> nextNextwentupaframebecausepreviousframefinishedFrom:/Users/benwoodward/dev/carrierwave/lib/carrierwave/mounter.rb@line88CarrierWave::Mounter#remote_urls=:71:defremote_urls=(urls)72:returnifnoturlsorurls==""orurls.all?(&:blank?)73:74:@remote_urls=urls75:@download_error=nil76:@integrity_error=nil77:78:@uploaders=urls.mapdo|url|79:uploader=blank_uploader80:uploader.download!(url)81:uploader82:end83:84:rescueCarrierWave::DownloadError=>e85:@download_error=e86:raiseeunlessoption(:ignore_download_errors)87:rescueCarrierWave::ProcessingError=>e=>88:@processing_error=e89:raiseeunlessoption(:ignore_processing_errors)90:rescueCarrierWave::IntegrityError=>e91:@integrity_error=e92:raiseeunlessoption(:ignore_integrity_errors)93:endpry(#<CarrierWave::Mounter>)> e=>#<CarrierWave::ProcessingError: Failed to manipulate with rmagick, maybe it is not an image?>pry(#<CarrierWave::Mounter>)> option(:ignore_processing_errors)=>true
Oh dear. Turns out CarrierWave has some configuration options that I didn’t see mentioned in the documentation. Perhaps I should have researched the configuration options first, oh well. Next step, switch the errors back on in development…
Pry is an extremely powerful tool for debugging Ruby apps and also learning about how codebases work and always my go-to tool for these kind of scenarios. If you found this useful, have any suggestions about how I might have solved this problem efficiently, or even Pry tips; please let me know in the comments.