Exception: Net::IMAP::ResponseParseError
- Defined in:
- lib/net/imap/errors.rb
Overview
Error raised when a response from the server is non-parsable.
NOTE: Parser attributes are provided for debugging and inspection only. Their names and semantics may change incompatibly in any release.
Instance Attribute Summary collapse
-
#lex_state ⇒ Object
readonly
The parser’s lex state.
-
#parser_class ⇒ Object
readonly
Net::IMAP::ResponseParser, unless a custom parser produced the error.
-
#pos ⇒ Object
readonly
The parser’s byte position in #string when the error was raised.
-
#string ⇒ Object
readonly
The full raw response string which was being parsed.
-
#token ⇒ Object
readonly
The last lexed token.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Returns true when all attributes are equal, except for #backtrace and #backtrace_locations which are replaced with #parser_methods.
-
#detailed_message(parser_state: Net::IMAP.debug, parser_backtrace: false, highlight: default_highlight_from_env, highlight_no_color: (ENV["NO_COLOR"] || "") != "") ⇒ Object
When
parser_stateis true, debug info about the parser state is included. -
#initialize(message = "unspecified parse error", parser_class: Net::IMAP::ResponseParser, parser_state: nil, string: parser_state&.at(0), lex_state: parser_state&.at(1), pos: parser_state&.at(2), token: parser_state&.at(3)) ⇒ ResponseParseError
constructor
A new instance of ResponseParseError.
-
#parser_methods ⇒ Object
Lists the methods (from #backtrace_locations or #backtrace) called on parser_class (since ruby 3.4) or which have “net/imap/response_parser” in the path (before ruby 3.4).
- #processed_string ⇒ Object
- #remaining_string ⇒ Object
Constructor Details
#initialize(message = "unspecified parse error", parser_class: Net::IMAP::ResponseParser, parser_state: nil, string: parser_state&.at(0), lex_state: parser_state&.at(1), pos: parser_state&.at(2), token: parser_state&.at(3)) ⇒ ResponseParseError
Returns a new instance of ResponseParseError.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/net/imap/errors.rb', line 126 def initialize( = "unspecified parse error", parser_class: Net::IMAP::ResponseParser, parser_state: nil, string: parser_state&.at(0), # see ParserUtils#parser_state lex_state: parser_state&.at(1), # see ParserUtils#parser_state pos: parser_state&.at(2), # see ParserUtils#parser_state token: parser_state&.at(3)) # see ParserUtils#parser_state @parser_class = parser_class @string = string @pos = pos @lex_state = lex_state @token = token super() end |
Instance Attribute Details
#lex_state ⇒ Object (readonly)
The parser’s lex state
NOTE: This attribute is provided for debugging and inspection only. Its name and semantics may change incompatibly in any release.
115 116 117 |
# File 'lib/net/imap/errors.rb', line 115 def lex_state @lex_state end |
#parser_class ⇒ Object (readonly)
Net::IMAP::ResponseParser, unless a custom parser produced the error.
100 101 102 |
# File 'lib/net/imap/errors.rb', line 100 def parser_class @parser_class end |
#pos ⇒ Object (readonly)
The parser’s byte position in #string when the error was raised.
NOTE: This attribute is provided for debugging and inspection only. Its name and semantics may change incompatibly in any release.
109 110 111 |
# File 'lib/net/imap/errors.rb', line 109 def pos @pos end |
#string ⇒ Object (readonly)
The full raw response string which was being parsed.
103 104 105 |
# File 'lib/net/imap/errors.rb', line 103 def string @string end |
#token ⇒ Object (readonly)
The last lexed token
May be nil when the parser has accepted the last token and peeked at the next byte without generating a token.
NOTE: This attribute is provided for debugging and inspection only. Its name and semantics may change incompatibly in any release.
124 125 126 |
# File 'lib/net/imap/errors.rb', line 124 def token @token end |
Instance Method Details
#==(other) ⇒ Object
Returns true when all attributes are equal, except for #backtrace and #backtrace_locations which are replaced with #parser_methods. This allows deserialized errors to be compared.
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/net/imap/errors.rb', line 197 def ==(other) return false if self.class != other.class methods = parser_methods other_methods = other.parser_methods == other. && methods == other_methods && string == other.string && pos == other.pos && lex_state == other.lex_state && token == other.token end |
#detailed_message(parser_state: Net::IMAP.debug, parser_backtrace: false, highlight: default_highlight_from_env, highlight_no_color: (ENV["NO_COLOR"] || "") != "") ⇒ Object
When parser_state is true, debug info about the parser state is included. Defaults to the value of Net::IMAP.debug.
When parser_backtrace is true, a simplified backtrace is included, 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.
When highlight is not explicitly set, highlights may be enabled automatically, based on TERM and FORCE_COLOR environment variables.
By default, highlight uses colors from the basic ANSI palette. When highlight_no_color is true or the NO_COLOR environment variable is not empty, only monochromatic highlights are used: bold, underline, etc.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/net/imap/errors.rb', line 155 def (parser_state: Net::IMAP.debug, parser_backtrace: false, highlight: default_highlight_from_env, highlight_no_color: (ENV["NO_COLOR"] || "") != "", **) return super unless parser_state || parser_backtrace msg = super.dup esc = !highlight ? ESC_NO_HL : highlight_no_color ? ESC_NO_COLOR : ESC_COLORS hl = ->str { str % esc } val = ->str, val { hl[val.nil? ? "%{nil}%%p%{/nil}" : str] % val } if parser_state && (string || pos || lex_state || token) msg << hl["\n %{key}processed %{/key}: "] << val["%{val}%%p%{/val}", processed_string] msg << hl["\n %{key}remaining %{/key}: "] << val["%{alt}%%p%{/alt}", remaining_string] msg << hl["\n %{key}pos %{/key}: "] << val["%{val}%%p%{/val}", pos] msg << hl["\n %{key}lex_state %{/key}: "] << val["%{sym}%%p%{/sym}", lex_state] msg << hl["\n %{key}token %{/key}: "] << val[ "%{sym}%%<symbol>p%{/sym} => %{val}%%<value>p%{/val}", token&.to_h ] end if parser_backtrace normalized_parser_backtrace.each do |idx, path, lineno, label, base_label| msg << "\n %s: %s (%s:%d)" % [ hl["%{key}caller[%{/key}%{idx}%%2d%{/idx}%{key}]%{/key}"] % idx, hl["%{label}%%-30s%{/label}"] % base_label, File.basename(path, ".rb"), lineno ] end end msg rescue => error msg ||= super.dup msg << "\n BUG in %s#%s: %s" % [self.class, __method__, error.] msg end |
#parser_methods ⇒ Object
Lists the methods (from #backtrace_locations or #backtrace) called on 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.
213 |
# File 'lib/net/imap/errors.rb', line 213 def parser_methods = normalized_parser_backtrace.map(&:last) |
#processed_string ⇒ Object
191 |
# File 'lib/net/imap/errors.rb', line 191 def processed_string = string && pos && string[...pos] |
#remaining_string ⇒ Object
192 |
# File 'lib/net/imap/errors.rb', line 192 def remaining_string = string && pos && string[pos..] |