Skip to content

Commit

Permalink
Merge 429e12b into b70bc73
Browse files Browse the repository at this point in the history
  • Loading branch information
pomier committed Jan 20, 2019
2 parents b70bc73 + 429e12b commit c2a8e73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/exception_notifier/slack_notifier.rb
Expand Up @@ -45,7 +45,8 @@ def call(exception, options={})
fields.push({ title: 'Hostname', value: Socket.gethostname })

if exception.backtrace
formatted_backtrace = "```#{exception.backtrace.first(@backtrace_lines).join("\n")}```"
backtrace = clean_backtrace(exception)
formatted_backtrace = "```#{backtrace.first(@backtrace_lines).join("\n")}```"
fields.push({ title: 'Backtrace', value: formatted_backtrace })
end

Expand Down
7 changes: 6 additions & 1 deletion test/exception_notifier/slack_notifier_test.rb
Expand Up @@ -7,6 +7,7 @@ def setup
@exception = fake_exception
@exception.stubs(:backtrace).returns(fake_backtrace)
@exception.stubs(:message).returns('exception message')
ExceptionNotifier::SlackNotifier.any_instance.stubs(:clean_backtrace).returns(fake_cleaned_backtrace)
Socket.stubs(:gethostname).returns('example.com')
end

Expand Down Expand Up @@ -195,6 +196,10 @@ def fake_backtrace
]
end

def fake_cleaned_backtrace
fake_backtrace[2..-1]
end

def fake_notification(exception = @exception, notification_options = {}, data_string = nil, expected_backtrace_lines = 10, additional_fields = [])
exception_name = "*#{exception.class.to_s =~ /^[aeiou]/i ? 'An' : 'A'}* `#{exception.class.to_s}`"
if notification_options[:env].nil?
Expand All @@ -214,7 +219,7 @@ def fake_notification(exception = @exception, notification_options = {}, data_st
fields = [ { title: 'Exception', value: exception.message} ]
fields.push({ title: 'Hostname', value: 'example.com' })
if exception.backtrace
formatted_backtrace = "```#{exception.backtrace.first(expected_backtrace_lines).join("\n")}```"
formatted_backtrace = "```#{fake_cleaned_backtrace.first(expected_backtrace_lines).join("\n")}```"
fields.push({ title: 'Backtrace', value: formatted_backtrace })
end
fields.push({ title: 'Data', value: "```#{data_string}```" }) if data_string
Expand Down

0 comments on commit c2a8e73

Please sign in to comment.