FIX: ensures errors in report initialization fail nicely (#6392)

This commit is contained in:
Joffrey JAFFEUX 2018-09-13 17:36:55 +02:00 committed by GitHub
parent 18fcd483f2
commit a6502ce879
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -176,6 +176,13 @@ class Report
report.error = :timeout
end
rescue Exception => e
# ensures that if anything unexpected prevents us from
# creating a report object we fail elegantly and log an error
if !report
Rails.logger.error("Couldnt create report `#{type}`: <#{e.class} #{e.message}>")
return nil
end
report.error = :exception
# given reports can be added by plugins we dont want dashboard failures

View File

@ -813,6 +813,22 @@ describe Report do
end
end
describe "unexpected error on report initialization" do
it "returns no report" do
class ReportInitError < StandardError; end
Report.stubs(:new).raises(ReportInitError.new("x"))
Rails.logger.expects(:error)
.with('Couldnt create report `signups`: <ReportInitError x>')
.once
report = Report.find('signups')
expect(report).to be_nil
end
end
describe 'posts' do
let(:report) { Report.find('posts') }