carrierwaveuploader/carrierwave · error · CarrierWave::IntegrityError
errors.messages.max_height_error
Error message
errors.messages.max_height_error
What it means
Raised as CarrierWave::IntegrityError when check_dimensions! sees an image taller than the upper bound of height_range (message errors.messages.max_height_error, bound formatted with delimiters). It is the last branch of the elsif chain (width bounds are checked first), applies to the base version only, and requires an image module (MiniMagick/RMagick/Vips) to supply height.
Source
Thrown at lib/carrierwave/uploader/dimension.rb:60
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
- Raise the ceiling (height_range 100..8000) or cap at nil: height_range 100..nil, and downscale with process resize_to_limit: [nil, 2000] for stored versions instead of rejecting
- Rescue CarrierWave::IntegrityError and return a clear 'image too tall, max X px' error
- Enforce the same maximum in the client/upload widget before submission
Example fix
# before class ScreenshotUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick height_range 600..2000 # 6000px full-page capture -> IntegrityError max_height_error end # after class ScreenshotUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick process resize_to_limit: [nil, 4000] height_range 100..nil end
Defensive patterns
Strategy: validation
Validate before calling
require 'fastimage' MAX_H = 2000 h = FastImage.size(params[:image].path)&.last return render_error(:too_tall) if h && h > MAX_H
Type guard
def within_height_range?(path, range) _, h = FastImage.size(path) !h.nil? && (range.begin.nil? || h >= range.begin) && (range.end.nil? || h <= 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
- Use resize_to_limit to cap stored height instead of rejecting tall originals
- Cap dimensions in the client/upload widget before POSTing large files
- Set height ceilings per uploader based on real content (screenshots need much taller caps than avatars)
When it happens
Trigger: Declaring height_range 600..2000 and uploading a 6000px-tall scroll-length screenshot or full-page capture; tall posters exported at print resolution.
Common situations: Screenshot-heavy products where full-page captures far exceed limits meant for photos; memory-driven caps (huge dimensions blow up processing) rejecting legitimate uploads; limits copied between uploaders with different content profiles.
Related errors
- errors.messages.min_height_error
- errors.messages.min_width_error
- errors.messages.max_width_error
- errors.messages.content_type_allowlist_error
- errors.messages.content_type_denylist_error
AI-assisted analysis of carrierwaveuploader/carrierwave@b5f0abe10e (2026-08-21).
Data as JSON: /api/errors/6a5d5db0c610e87f.
Report an issue: GitHub.