123456789_123456789_123456789_123456789_123456789_

Exception: Net::IMAP::ResponseParseError

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Error, StandardError
Instance Chain:
self, Error, StandardError
Inherits: Net::IMAP::Error
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.

Constant Summary

  • ESC_COLORS = private

    ANSI highlights, with color

    # File 'lib/net/imap/errors.rb', line 87
    Hash.new(&default_highlight).update(
      reset: "\e[m",
      key:   "\e[95m",      # bright magenta
      idx:   "\e[34m",      # blue
      val:   "\e[36;40m",   # cyan on black (to ensure contrast)
      alt:   "\e[1;33;40m", # bold; yellow on black
      sym:   "\e[33;40m",   # yellow on black
      label: "\e[1m",       # bold
      nil:   "\e[35m",      # magenta
    ).freeze
  • ESC_NO_COLOR = private

    ANSI highlights, but no colors

    # File 'lib/net/imap/errors.rb', line 77
    Hash.new(&default_highlight).update(
      reset: "\e[m",
      val:   "\e[1m",   # bold
      alt:   "\e[1;4m", # bold and underlined
      sym:   "\e[1m",   # bold
      label: "\e[1m",   # bold
    ).freeze
  • ESC_NO_HL = private

    returns “” for all highlights

    # File 'lib/net/imap/errors.rb', line 59
    Hash.new("").freeze

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(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

[ GitHub ]

  
# File 'lib/net/imap/errors.rb', line 126

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

Instance Attribute Details

#lex_state (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.

[ GitHub ]

  
# File 'lib/net/imap/errors.rb', line 115

attr_reader :lex_state

#parser_class (readonly)

ResponseParser, unless a custom parser produced the error.

[ GitHub ]

  
# File 'lib/net/imap/errors.rb', line 100

attr_reader :parser_class

#pos (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.

[ GitHub ]

  
# File 'lib/net/imap/errors.rb', line 109

attr_reader :pos

#string (readonly)

The full raw response string which was being parsed.

[ GitHub ]

  
# File 'lib/net/imap/errors.rb', line 103

attr_reader :string

#token (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.

[ GitHub ]

  
# File 'lib/net/imap/errors.rb', line 124

attr_reader :token

Instance Method Details

#default_highlight_from_env (private)

[ GitHub ]

  
# File 'lib/net/imap/errors.rb', line 203

def default_highlight_from_env
  (ENV["FORCE_COLOR"] || "") !~ /\A(?:0|)\z/ ||
    (ENV["TERM"] || "") !~ /\A(?:dumb|unknown|)\z/i
end

#detailed_message(parser_state: Net::IMAP.debug, parser_backtrace: false, highlight: default_highlight_from_env, highlight_no_color: (ENV["NO_COLOR"] || "") != "")

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 ::Net::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.

[ GitHub ]

  
# File 'lib/net/imap/errors.rb', line 155

def detailed_message(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
    backtrace_locations&.each_with_index do |loc, idx|
      next  if    loc.base_label.include? "parse_error"
      break if    loc.base_label == "parse"
      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  %s: %s (%s:%d)" % [
        hl["%{key}caller[%{/key}%{idx}%%2d%{/idx}%{key}]%{/key}"] % idx,
        hl["%{label}%%-30s%{/label}"] % 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

#processed_string

[ GitHub ]

  
# File 'lib/net/imap/errors.rb', line 198

def processed_string = string && pos && string[...pos]

#remaining_string

[ GitHub ]

  
# File 'lib/net/imap/errors.rb', line 199

def remaining_string = string && pos && string[pos..]