Don't include stack backtraces on xml errors when importing traces

This commit is contained in:
Anton Khorev 2024-09-19 18:38:50 +03:00
parent f2e302c6a8
commit 81bac0b09b
4 changed files with 36 additions and 0 deletions

View file

@ -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 }

BIN
test/gpx/fixtures/jpg.gpx Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

View file

@ -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