carrierwaveuploader/carrierwave · error · CarrierWave::ProcessingError

errors.messages.processing_error

Error message

errors.messages.processing_error

What it means

Raised as CarrierWave::ProcessingError (with the errors.messages.processing_error i18n message) by CarrierWave::MiniMagick#manipulate! when an image operation fails with ::MiniMagick::Error or ::MiniMagick::Invalid. The rescue deliberately re-raises errors whose message shows ImageMagick itself is missing ('You must have ... installed', 'is not installed', 'executable not found', 'delegate failed'); everything else (corrupt input, unsupported format, failed convert run) becomes this generic processing error.

Source

Thrown at lib/carrierwave/processing/mini_magick.rb:298

    #
    # [MiniMagick::Image] manipulations to perform
    #
    # === Raises
    #
    # [CarrierWave::ProcessingError] if manipulation failed.
    #
    def manipulate!
      cache_stored_file! if !cached?
      image = ::MiniMagick::Image.open(current_path)

      image = yield(image)
      FileUtils.mv image.path, current_path

      ::MiniMagick::Image.new(current_path).identify
    rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
      raise e if e.message =~ /(You must have .+ installed|is not installed|executable not found|delegate failed)/
      message = I18n.translate(:"errors.messages.processing_error")
      raise CarrierWave::ProcessingError, message
    ensure
      image.destroy! if image
    end

    # Process the image with MiniMagick, using the ImageProcessing gem. This
    # method will build a "convert" ImageMagick command and execute it on the
    # current image.
    #
    # === Gotcha
    #
    # This method assumes that the object responds to +current_path+.
    # Any class that this module is mixed into must have a +current_path+ method.
    # CarrierWave::Uploader does, so you won't need to worry about this in
    # most cases.
    #
    # === Yields
    #
    # [ImageProcessing::Builder] use it to define processing to be performed

View on GitHub (pinned to b5f0abe10e)

Solutions

  1. Sniff the real content type with Marcel (or a MiniMagick identify probe) before caching/processing and reject non-images
  2. Rescue CarrierWave::ProcessingError in the controller/uploader callback and reject the upload with a friendly message
  3. Verify ImageMagick is installed and the needed delegates exist on the server (convert -list format) — missing-binary errors re-raise with their own message
  4. For policy/delegate issues, adjust /etc/ImageMagick-*/policy.xml or install the delegate packages

Example fix

# before
process resize_to_fill: [200, 200] # corrupt file -> ProcessingError

# after
process resize_to_fill: [200, 200]

def validate_content_type(file)
  type = Marcel::MimeType.from_path(file.path, magic: true)
  raise CarrierWave::ProcessingError, :invalid_image unless type.start_with?('image/')
end
Defensive patterns

Strategy: try-catch

Validate before calling

require 'marcel'

def processable_image?(path)
  Marcel::MimeType.from_path(path, magic: true).start_with?('image/')
end

before_cache do |file|
  raise CarrierWave::ProcessingError, :invalid_image unless processable_image?(file.path)
end

Try / catch

begin
  uploader.cache!(file)
  uploader.store!
rescue CarrierWave::ProcessingError
  errors.add(:image, :processing_failed)
end

Prevention

When it happens

Trigger: Declaring process in an uploader with the mini_magick module (e.g. process resize_to_fill: [200, 200]) and uploading a file the 'convert' binary cannot handle: a corrupted or zero-byte image, a non-image renamed to .jpg, or an obscure format ImageMagick lacks a coder for on the server.

Common situations: User uploads a file whose extension lies about its content; a truncated upload; hosting environments (slim Docker images, Alpine) missing ImageMagick delegates for the format being processed; upgrading ImageMagick changes format support or policy.xml restrictions.

Related errors


AI-assisted analysis of carrierwaveuploader/carrierwave@b5f0abe10e (2026-08-21). Data as JSON: /api/errors/d4d686d9ff17a9af. Report an issue: GitHub.