From db5373a87ceb599b157ab3f21ffcd9c0a1ca8e9f Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Thu, 23 Jan 2020 14:04:06 -0300 Subject: [PATCH] UX: Invalid CSV error message now includes information about the malformed line (#8773) * UX: Invalid CSV error message now includes information about the malformed line * Update config/locales/server.en.ym and use line_number instead of lineno Co-Authored-By: Robin Ward Co-authored-by: Robin Ward --- app/controllers/admin/badges_controller.rb | 4 +++- config/locales/server.en.yml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/badges_controller.rb b/app/controllers/admin/badges_controller.rb index 85937e46538..a63d33bda64 100644 --- a/app/controllers/admin/badges_controller.rb +++ b/app/controllers/admin/badges_controller.rb @@ -44,11 +44,13 @@ class Admin::BadgesController < Admin::AdminController raise Discourse::InvalidParameters if csv_file.try(:tempfile).nil? || badge.nil? batch_number = 1 + line_number = 1 batch = [] File.open(csv_file) do |csv| csv.each_line do |email_line| batch.concat CSV.parse_line(email_line) + line_number += 1 # Split the emails in batches of 200 elements. full_batch = csv.lineno % (BadgeGranter::MAX_ITEMS_FOR_DELTA * batch_number) == 0 @@ -64,7 +66,7 @@ class Admin::BadgesController < Admin::AdminController head :ok rescue CSV::MalformedCSVError - render_json_error I18n.t('badges.mass_award.errors.invalid_csv'), status: 400 + render_json_error I18n.t('badges.mass_award.errors.invalid_csv', line_number: line_number), status: 400 end def badge_types diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 90653d84bbf..6fa9ceacc7e 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -4134,7 +4134,7 @@ en: badges: mass_award: errors: - invalid_csv: We couldn't read that CSV file. Please confirm it has one email per line. + invalid_csv: We encountered an error on line %{line_number}. Please confirm the CSV has one email per line. editor: name: Editor description: First post edit