Skip to content

Commit

Permalink
Truncate Exception Messages if needed.
Browse files Browse the repository at this point in the history
If an exception occurs, such as a `Mysql2::Error::ConnectionError`, where the query is extremely long, this can cause the payload to exceed what Bugsnag will accept and throw a `Errno::EPIPE: Broken pipe` error when trying to send the request to Bugsnag.

A number of elements are already trimmed when the payload is too large, including meta data, stacktrace code, etc. However, the exception messages were not being trimmed.

This commit adds exception message trimming to `Bugsnag::Helpers.trim_if_needed`, which should help reduce errors when the queries causing the errors are exceptionally long.
  • Loading branch information
joshuapinter committed Oct 8, 2020
1 parent fe82dca commit efe36f0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/bugsnag/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ def self.trim_if_needed(value)

return value unless payload_too_long?(value)

# Truncate exception messages
reduced_value = truncate_exception_messages(value)
return reduced_value unless payload_too_long?(reduced_value)

# Trim metadata
reduced_value = trim_metadata(value)
reduced_value = trim_metadata(reduced_value)
return reduced_value unless payload_too_long?(reduced_value)

# Trim code from stacktrace
Expand Down Expand Up @@ -71,6 +75,15 @@ def self.deep_merge!(l_hash, r_hash)

TRUNCATION_INFO = '[TRUNCATED]'

##
# Truncate exception messages
def self.truncate_exception_messages(payload)
extract_exception(payload) do |exception|
exception[:message] = trim_as_string(exception[:message])
end
payload
end

##
# Remove all code from stacktraces
def self.trim_stacktrace_code(payload)
Expand Down

0 comments on commit efe36f0

Please sign in to comment.