no sentry noise on malformed gradebook imports

closes FOO-1328
flag=none

TEST PLAN:
  1) upload a badly encoded file for gradebook
  2) the job should fail, as it already does,
     but without notifying sentry (logs still happen)

Change-Id: I3b09f93a2138bd843e0229bf25e15f54593879b7
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/255081
Reviewed-by: Rob Orton <rob@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Ethan Vizitei <evizitei@instructure.com>
Product-Review: Ethan Vizitei <evizitei@instructure.com>
This commit is contained in:
Ethan Vizitei 2020-12-14 14:43:49 -06:00
parent 3989c4f602
commit a1307ff8b7
3 changed files with 25 additions and 0 deletions

View File

@ -52,6 +52,11 @@ class GradebookImporter
def self.create_from(progress, gradebook_upload, user, attachment)
self.new(gradebook_upload, attachment, user, progress).parse!
rescue CSV::MalformedCSVError => e
Canvas::Errors.capture_exception(:gradebook_import, e, :info)
# this isn't actually "retryable", but this error will make sure
# the job is marked "failed" without generating alarm noise.
raise Delayed::RetriableError, "Gradebook import did not parse cleanly"
end
def initialize(upload=nil, attachment=nil, user=nil, progress=nil)

6
spec/fixtures/gradebooks/wat.csv vendored Normal file
View File

@ -0,0 +1,6 @@
"1,asdf,fdsa \"rew qwer q\" ljhg,zxcv"
<20>
<xml>
<value>I'm not actually a csv!</value>
</xml>
qwerqqwerqwer,qwerq,wer,qwz,xcvz;;fjbnsaba;skdfj;as,asdf
Can't render this file because it contains an unexpected character in line 1 and column 15.

View File

@ -89,6 +89,16 @@ describe GradebookImporter do
expect(@gi.students.length).to eq 2
end
it "expects and deals with invalid upload files" do
user = user_model
progress = Progress.create!(tag: "test", context: @user)
upload = GradebookUpload.new
upload = GradebookUpload.create!(course: gradebook_course, user: gradebook_user, progress: progress)
expect do
GradebookImporter.create_from(progress, upload, user, invalid_gradebook_contents)
end.to raise_error(Delayed::RetriableError)
end
context 'when dealing with a file containing semicolon field separators' do
context 'with interspersed commas to throw you off' do
before(:each) do
@ -1743,6 +1753,10 @@ describe GradebookImporter do
attachment_with_file(File.join(File.dirname(__FILE__), %w(.. fixtures gradebooks basic_course_with_sis_login_id.csv)))
end
def invalid_gradebook_contents
attachment_with_file(File.join(File.dirname(__FILE__), %w(.. fixtures gradebooks wat.csv)))
end
def attachment_with
a = attachment_model
file = Tempfile.new("gradebook_import.csv")