Merge remote-tracking branch 'upstream/pull/5226'

This commit is contained in:
Tom Hughes 2024-09-20 19:19:13 +01:00
commit 0bf56cd3ce
5 changed files with 37 additions and 1 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 UserMailer.gpx_failure(trace, "0 points parsed ok. Do they all have lat,lng,alt,timestamp?").deliver
trace.destroy trace.destroy
end end
rescue XML::Error => e
logger.info e.to_s
UserMailer.gpx_failure(trace, e).deliver
trace.destroy
rescue StandardError => e rescue StandardError => e
logger.info e.to_s logger.info e.to_s
e.backtrace.each { |l| logger.info l } e.backtrace.each { |l| logger.info l }

View file

@ -57,7 +57,7 @@ module GPX
when "application/x-bzip" then io = Bzip2::FFI::Reader.open(@file) when "application/x-bzip" then io = Bzip2::FFI::Reader.open(@file)
end end
parse_file(XML::Reader.io(io), &block) parse_file(XML::Reader.io(io, :options => XML::Parser::Options::NOERROR), &block)
end end
end end

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 email = ActionMailer::Base.deliveries.last
assert_equal trace.user.email, email.to[0] assert_equal trace.user.email, email.to[0]
assert_match(/failure/, email.subject) 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 ActionMailer::Base.deliveries.clear
end end