class Net::IMAP::ResponseParseError
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.
Attributes
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.
Net::IMAP::ResponseParser, unless a custom parser produced the error.
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.
The full raw response string which was being parsed.
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.
Public Class Methods
Source
# File lib/net/imap/errors.rb, line 85 def initialize(message = "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(message) end
Public Instance Methods
Source
# File lib/net/imap/errors.rb, line 106 def detailed_message(parser_state: Net::IMAP.debug, parser_backtrace: false, **) return super unless parser_state || parser_backtrace msg = super.dup if parser_state && (string || pos || lex_state || token) msg << "\n processed : %p" % processed_string msg << "\n remaining : %p" % remaining_string msg << "\n pos : %p" % pos msg << "\n lex_state : %p" % lex_state msg << "\n token : " if token msg << "%p => %p" % [token.symbol, token.value] else msg << "nil" end end if parser_backtrace 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) msg << "\n caller[%2d]: %-30s (%s:%d)" % [ idx, loc.base_label, File.basename(loc.path, ".rb"), loc.lineno ] end end msg rescue => error msg ||= super.dup msg << "\n BUG in %s#%s: %s" % [self.class, __method__, error.detailed_message] msg end
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 which belong to methods in parser_class. Most parser method names are based on rules in the IMAP grammar.
Source
# File lib/net/imap/errors.rb, line 144 def processed_string = string && pos && string[...pos] def remaining_string = string && pos && string[pos..] end # Superclass of all errors used to encapsulate "fail" responses # from the server. class ResponseError < Error # The response that caused this error attr_accessor :response def initialize(response) @response = response super @response.data.text end end # Error raised upon a "NO" response from the server, indicating # that the client command could not be completed successfully. class NoResponseError < ResponseError end # Error raised upon a "BAD" response from the server, indicating # that the client command violated the IMAP protocol, or an internal # server failure has occurred. class BadResponseError < ResponseError end # Error raised upon a "BYE" response from the server, indicating # that the client is not being allowed to login, or has been timed # out due to inactivity. class ByeResponseError < ResponseError end # Error raised when the server sends an invalid response. # # This is different from UnknownResponseError: the response has been # rejected. Although it may be parsable, the server is forbidden from # sending it in the current context. The client should automatically # disconnect, abruptly (without logout). # # Note that InvalidResponseError does not inherit from ResponseError: it # can be raised before the response is fully parsed. A related # ResponseParseError or ResponseError may be the #cause. class InvalidResponseError < Error end # Error raised upon an unknown response from the server. # # This is different from InvalidResponseError: the response may be a # valid extension response and the server may be allowed to send it in # this context, but Net::IMAP either does not know how to parse it or # how to handle it. This could result from enabling unknown or # unhandled extensions. The connection may still be usable, # but—depending on context—it may be prudent to disconnect. class UnknownResponseError < ResponseError end RESPONSE_ERRORS = Hash.new(ResponseError) # :nodoc: RESPONSE_ERRORS["NO"] = NoResponseError RESPONSE_ERRORS["BAD"] = BadResponseError end
Source
# File lib/net/imap/errors.rb, line 145 def remaining_string = string && pos && string[pos..] end