mirror of
https://github.com/discourse/discourse.git
synced 2025-02-21 00:41:55 +08:00
FIX: ensures errors in report initialization fail nicely (#6392)
This commit is contained in:
parent
18fcd483f2
commit
a6502ce879
@ -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("Couldn’t create report `#{type}`: <#{e.class} #{e.message}>")
|
||||
return nil
|
||||
end
|
||||
|
||||
report.error = :exception
|
||||
|
||||
# given reports can be added by plugins we don’t want dashboard failures
|
||||
|
@ -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('Couldn’t 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') }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user