Skip to content

Commit

Permalink
rescue CSV error and display it to user
Browse files Browse the repository at this point in the history
  • Loading branch information
lisa-durand committed Feb 18, 2025
1 parent fb028ca commit 0f0ee73
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/administrateurs/types_de_champ_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ def import_referentiel

type_de_champ = draft.find_and_ensure_exclusive_use(params[:stable_id])

csv_to_code = ACSV::CSV.new_for_ruby3(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true).map(&:to_h)
begin
csv_to_code = ACSV::CSV.new_for_ruby3(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true).map(&:to_h)
rescue CSV::MalformedCSVError
return flash[:alert] = "Importation impossible : le fichier est mal formaté"

Check warning on line 159 in app/controllers/administrateurs/types_de_champ_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/types_de_champ_controller.rb#L159

Added line #L159 was not covered by tests
end

return flash[:alert] = "Importation impossible : votre fichier CSV fait plus de #{helpers.number_with_delimiter(CSV_MAX_LINES)} lignes" if csv_to_code.size > CSV_MAX_LINES

Expand Down

0 comments on commit 0f0ee73

Please sign in to comment.