shrinerb / shrine

File Attachment toolkit for Ruby applications
https://shrinerb.com
MIT License
3.18k stars 275 forks source link

SHRINE WARNING: Error occurred when attempting to extract image dimensions: #<FastImage::UnknownImageType: FastImage::UnknownImageType> not using error handler #566

Closed h0jeZvgoxFepBQ2C closed 2 years ago

h0jeZvgoxFepBQ2C commented 2 years ago

Brief Description

During an image check, we get an unhandled exception:

SHRINE WARNING: Error occurred when attempting to extract image dimensions: #<FastImage::UnknownImageType: FastImage::UnknownImageType>

Expected behavior

Use the error callback

Actual behavior

Is raising an exception

Simplest self-contained example code to demonstrate issue

I guess we just have to add FastImage::UnknownImageType to the rescue clause here:

https://github.com/shrinerb/shrine/blob/f99fe7d10ed4c276d5afdca46194bc3ac9c76b95/lib/shrine/plugins/store_dimensions.rb#L121

System configuration

Ruby version: 2.6.6

Shrine version:

Workarount:

  plugin :store_dimensions, analyzer: -> (io, analyzers) do
    begin
      dimensions   = analyzers[:fastimage].call(io)   # try extracting dimensions with FastImage
    rescue => e
      puts e
    end
    dimensions
  end
h0jeZvgoxFepBQ2C commented 2 years ago

Sorry, I was just wrong.