Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/net/imap/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ def initialize(message = "unspecified parse error",
# included. Defaults to the value of Net::IMAP.debug.
#
# When +parser_backtrace+ is true, a simplified backtrace is included,
# containing only frames which belong to methods in parser_class. Most
# parser method names are based on rules in the IMAP grammar.
# containing only frames for methods in parser_class (since ruby 3.4) or
# which have "net/imap/response_parser" in the path (before ruby 3.4).
# Most parser method names are based on rules in the IMAP grammar.
def detailed_message(parser_state: Net::IMAP.debug,
parser_backtrace: false,
**)
Expand All @@ -124,7 +125,11 @@ def detailed_message(parser_state: Net::IMAP.debug,
backtrace_locations&.each_with_index do |loc, idx|
next if loc.base_label.include? "parse_error"
break if loc.base_label == "parse"
next unless loc.label.include?(parser_class.name)
if loc.label.include?("#") # => Class#method, since ruby 3.4
next unless loc.label&.include?(parser_class.name)
else
next unless loc.path&.include?("net/imap/response_parser")
end
msg << "\n caller[%2d]: %-30s (%s:%d)" % [
idx,
loc.base_label,
Expand Down
9 changes: 9 additions & 0 deletions test/net/imap/test_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ def self.SGR(*attr) = CSI attr.join(?;), ?m
"#{BOLD}#{msg} (#{BOLD_UNDERLINE}#{name}#{RESET}#{BOLD})#{RESET}",
err.detailed_message(highlight: true)
)

# with parser_backtrace
Net::IMAP.debug = false
parser = Net::IMAP::ResponseParser.new
error = parser.parse("* 123 FETCH (UNKNOWN ...)\r\n") rescue $!
no_hl = error.detailed_message(parser_backtrace: true)
no_color = error.detailed_message(parser_backtrace: true, highlight: true)
assert_include no_hl, "caller[ 1]: %-30s (" % "msg_att"
assert_include no_color, "caller[ 1]: %-30s (" % "msg_att"
end

test "ResponseTooLargeError" do
Expand Down