Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use backtrace cleaner for Slack notifications #453

Merged
merged 1 commit into from Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/exception_notifier/slack_notifier.rb
Expand Up @@ -50,7 +50,8 @@ def deep_reject(hash, block)

def attchs(exception, clean_message, options)
text, data = information_from_options(exception.class, options)
fields = fields(clean_message, exception.backtrace, data)
backtrace = clean_backtrace(exception) if exception.backtrace
fields = fields(clean_message, backtrace, data)

[color: @color, text: text, fields: fields, mrkdwn_in: %w[text fields]]
end
Expand Down
7 changes: 6 additions & 1 deletion test/exception_notifier/slack_notifier_test.rb
Expand Up @@ -6,6 +6,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 @@ -192,6 +193,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}`"
if notification_options[:env].nil?
Expand All @@ -211,7 +216,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