Exception: JSONP3::JSONPathError
- Inherits:
-
StandardError
- Object
- StandardError
- JSONP3::JSONPathError
- Defined in:
- lib/json_p3/errors.rb
Overview
Base class for JSONPath exceptions that happen when parsing or evaluating a query.
Direct Known Subclasses
JSONPathNameError, JSONPathRecursionError, JSONPathSyntaxError, JSONPathTypeError
Constant Summary collapse
- FULL_MESSAGE =
((RUBY_VERSION.split(".")&.map(&:to_i) <=> [3, 2, 0]) || -1) < 1
Instance Method Summary collapse
- #detailed_message(highlight: true, **_kwargs) ⇒ Object
- #full_message(highlight: true, order: :top) ⇒ Object
-
#initialize(msg, token) ⇒ JSONPathError
constructor
A new instance of JSONPathError.
Constructor Details
#initialize(msg, token) ⇒ JSONPathError
Returns a new instance of JSONPathError.
11 12 13 14 |
# File 'lib/json_p3/errors.rb', line 11 def initialize(msg, token) super(msg) @token = token end |
Instance Method Details
#detailed_message(highlight: true, **_kwargs) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/json_p3/errors.rb', line 16 def (highlight: true, **_kwargs) if @token.query.strip.empty? "empty query" else lines = @token.query[...@token.start]&.lines or [""] # pleasing the type checker lineno = lines.length col = lines[-1].length pad = " " * lineno.to_s.length pointer = (" " * col) + ("^" * [@token.value.length, 1].max) <<~ENDOFMESSAGE.strip #{self.class}: #{} #{pad} -> '#{@token.query}' #{lineno}:#{col} #{pad} | #{lineno} | #{@token.query} #{pad} | #{pointer} #{highlight ? "\e[1m#{}\e[0m" : } ENDOFMESSAGE end end |
#full_message(highlight: true, order: :top) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/json_p3/errors.rb', line 35 def (highlight: true, order: :top) if FULL_MESSAGE # For Ruby < 3.2.0 "#{super}\n#{(highlight: highlight, order: order)}" else super end end |