activeadmin-plugins / active_admin_import

:paperclip: active_admin_import is based on activerecord-import gem - the most efficient way to import for ActiveAdmin
http://activeadmin-plugins.github.io/active_admin_import
MIT License
183 stars 101 forks source link

Fix errors with invalid csv #200

Closed BigG1947 closed 11 months ago

BigG1947 commented 11 months ago

We have 2 situation when raised errors without handling:

  1. Empty CSV and model has force_encoding: 'auto' In this case encoding detected automatically by

    def dynamic_encoding(data)
      CharDet.detect(data)['encoding']
    end

    But if data is empty string '' result will be nil. data.force_encoding(encoding_name) where data is empty string and encoding_name is nil raise TypeError: no implicit conversion of nil into String

  2. When we have invalid csv in which values exceeded headers activerecord_import gem raised ArgumentError:

    raise ArgumentError, "Number of values (#{arr.length}) exceeds number of columns (#{columns.length})"

    We can handle it in collection_action and return flash message to users