carrierwaveuploader/carrierwave · error · CarrierWave::IntegrityError

errors.messages.min_width_error

Error message

errors.messages.min_width_error

What it means

Raised as CarrierWave::IntegrityError when check_dimensions! sees an image narrower than the lower bound of the uploader's width_range (message errors.messages.min_width_error, with the bound formatted via number_to_delimited). The check only runs on the main version (version_name skipped), requires width/height support from CarrierWave::MiniMagick, RMagick, or Vips, and fires during caching before storage.

Source

Thrown at lib/carrierwave/uploader/dimension.rb:54

      #     def height_range
      #       1000..
      #     end
      #
      def height_range; end

    private

      def check_dimensions!(new_file)
        # NOTE: Skip the check for resized images
        return if version_name.present?
        return unless width_range || height_range

        unless respond_to?(:width) || respond_to?(:height)
          raise 'You need to include one of CarrierWave::MiniMagick, CarrierWave::RMagick, or CarrierWave::Vips to perform image dimension validation'
        end

        if width_range&.begin && width < width_range.begin
          raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.min_width_error", :min_width => ActiveSupport::NumberHelper.number_to_delimited(width_range.begin))
        elsif width_range&.end && width > width_range.end
          raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.max_width_error", :max_width => ActiveSupport::NumberHelper.number_to_delimited(width_range.end))
        elsif height_range&.begin && height < height_range.begin
          raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.min_height_error", :min_height => ActiveSupport::NumberHelper.number_to_delimited(height_range.begin))
        elsif height_range&.end && height > height_range.end
          raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.max_height_error", :max_height => ActiveSupport::NumberHelper.number_to_delimited(height_range.end))
        end
      end

    end # Dimension
  end # Uploader
end # CarrierWave

View on GitHub (pinned to b5f0abe10e)

Solutions

  1. Lower or drop the minimum: width_range 100..1600 (or nil) to accept the real minimum
  2. Validate dimensions client-side (or on upload forms) with the same bounds before submission
  3. Rescue CarrierWave::IntegrityError and turn it into a model error with a helpful message
  4. If small images should be upscaled instead of rejected, add a process step to resize to the minimum before validation

Example fix

# before
class AvatarUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick
  width_range 800..1600 # 600px upload -> IntegrityError min_width_error
end

# after
class AvatarUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick
  width_range 200..1600
end
Defensive patterns

Strategy: validation

Validate before calling

require 'fastimage'

MIN_W = 800
w, _h = FastImage.size(params[:image].path)
return render_error(:too_narrow) if w && w < MIN_W
# then assign to the uploader

Type guard

def within_width_range?(path, range)
  w, = FastImage.size(path)
  !w.nil? && (range.begin.nil? || w >= range.begin) && (range.end.nil? || w <= range.end)
end

Try / catch

begin
  record.save!
rescue CarrierWave::IntegrityError => e
  record.errors.add(:image, :dimensions_invalid, message: e.message)
  render :new
end

Prevention

When it happens

Trigger: Declaring width_range 800..1600 in an uploader (with an image module included) and uploading an image whose width is below 800 — e.g. a 400x300 avatar.

Common situations: Product requirements raise the minimum image size after launch and old clients still submit small ones; thumbnails/screenshots pasted at low resolution; cameras exporting smaller than expected; mobile crops producing narrow images.

Related errors


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