From: Anton Khorev Date: Thu, 19 Sep 2024 15:38:50 +0000 (+0300) Subject: Don't include stack backtraces on xml errors when importing traces X-Git-Tag: live~110^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/81bac0b09b2d03de76c8885f6d77c9297a3ead34?ds=sidebyside Don't include stack backtraces on xml errors when importing traces --- diff --git a/app/jobs/trace_importer_job.rb b/app/jobs/trace_importer_job.rb index 940dd6c79..48285cbc1 100644 --- a/app/jobs/trace_importer_job.rb +++ b/app/jobs/trace_importer_job.rb @@ -10,6 +10,10 @@ class TraceImporterJob < ApplicationJob UserMailer.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver trace.destroy end + rescue XML::Error => e + logger.info e.to_s + UserMailer.gpx_failure(trace, e).deliver + trace.destroy rescue StandardError => e logger.info e.to_s e.backtrace.each { |l| logger.info l } diff --git a/test/gpx/fixtures/jpg.gpx b/test/gpx/fixtures/jpg.gpx new file mode 100644 index 000000000..12dc8c4ab Binary files /dev/null and b/test/gpx/fixtures/jpg.gpx differ diff --git a/test/gpx/fixtures/jpg.gz.gpx b/test/gpx/fixtures/jpg.gz.gpx new file mode 100644 index 000000000..2742808e1 Binary files /dev/null and b/test/gpx/fixtures/jpg.gz.gpx differ diff --git a/test/jobs/trace_importer_job_test.rb b/test/jobs/trace_importer_job_test.rb index e1ddcc967..c6d44ecce 100644 --- a/test/jobs/trace_importer_job_test.rb +++ b/test/jobs/trace_importer_job_test.rb @@ -52,6 +52,38 @@ class TraceImporterJobTest < ActiveJob::TestCase email = ActionMailer::Base.deliveries.last assert_equal trace.user.email, email.to[0] assert_match(/failure/, email.subject) + assert_no_match(/Start tag expected/, email.text_part.body.to_s, "should not include parser error") + assert_match(%r{jobs/trace_importer_job\.rb}, email.text_part.body.to_s, "should include stack backtrace") + + ActionMailer::Base.deliveries.clear + end + + def test_parse_error_notification + trace = create(:trace, :inserted => false, :fixture => "jpg") + Rails.logger.silence do + TraceImporterJob.perform_now(trace) + end + + email = ActionMailer::Base.deliveries.last + assert_equal trace.user.email, email.to[0] + assert_match(/failure/, email.subject) + assert_match(/Start tag expected/, email.text_part.body.to_s, "should include parser error") + assert_no_match(%r{jobs/trace_importer_job\.rb}, email.text_part.body.to_s, "should not include stack backtrace") + + ActionMailer::Base.deliveries.clear + end + + def test_gz_parse_error_notification + trace = create(:trace, :inserted => false, :fixture => "jpg.gz") + Rails.logger.silence do + TraceImporterJob.perform_now(trace) + end + + email = ActionMailer::Base.deliveries.last + assert_equal trace.user.email, email.to[0] + assert_match(/failure/, email.subject) + assert_match(/Start tag expected/, email.text_part.body.to_s, "should include parser error") + assert_no_match(%r{jobs/trace_importer_job\.rb}, email.text_part.body.to_s, "should not include stack backtrace") ActionMailer::Base.deliveries.clear end