Exception: JSON5::Error
- Inherits:
-
StandardError
- Object
- StandardError
- JSON5::Error
- Defined in:
- lib/json5/errors.rb
Direct Known Subclasses
ConversionError, DepthError, EncodingError, LexError, LimitError, ParseError
Instance Attribute Summary collapse
-
#byte_offset ⇒ Object
readonly
Returns the value of attribute byte_offset.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#end_byte_offset ⇒ Object
readonly
Returns the value of attribute end_byte_offset.
-
#excerpt ⇒ Object
readonly
Returns the value of attribute excerpt.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#unexpected ⇒ Object
readonly
Returns the value of attribute unexpected.
Instance Method Summary collapse
-
#initialize(message = nil, code: "parse_error", filename: nil, byte_offset: nil, end_byte_offset: nil, line: nil, column: nil, unexpected: nil, expected: nil, excerpt: nil) ⇒ Error
constructor
A new instance of Error.
- #to_h ⇒ Object
- #with_context(filename: self.filename, byte_offset: self.byte_offset, end_byte_offset: self.end_byte_offset, line: self.line, column: self.column, excerpt: self.excerpt) ⇒ Object
Constructor Details
#initialize(message = nil, code: "parse_error", filename: nil, byte_offset: nil, end_byte_offset: nil, line: nil, column: nil, unexpected: nil, expected: nil, excerpt: nil) ⇒ Error
Returns a new instance of Error.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/json5/errors.rb', line 8 def initialize( = nil, code: "parse_error", filename: nil, byte_offset: nil, end_byte_offset: nil, line: nil, column: nil, unexpected: nil, expected: nil, excerpt: nil) @code = code.to_s.freeze @filename = filename @byte_offset = byte_offset @end_byte_offset = end_byte_offset @line = line @column = column @unexpected = unexpected @expected = expected&.map(&:to_s)&.freeze @excerpt = excerpt super( || @code) end |
Instance Attribute Details
#byte_offset ⇒ Object (readonly)
Returns the value of attribute byte_offset.
5 6 7 |
# File 'lib/json5/errors.rb', line 5 def byte_offset @byte_offset end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/json5/errors.rb', line 5 def code @code end |
#column ⇒ Object (readonly)
Returns the value of attribute column.
5 6 7 |
# File 'lib/json5/errors.rb', line 5 def column @column end |
#end_byte_offset ⇒ Object (readonly)
Returns the value of attribute end_byte_offset.
5 6 7 |
# File 'lib/json5/errors.rb', line 5 def end_byte_offset @end_byte_offset end |
#excerpt ⇒ Object (readonly)
Returns the value of attribute excerpt.
5 6 7 |
# File 'lib/json5/errors.rb', line 5 def excerpt @excerpt end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
5 6 7 |
# File 'lib/json5/errors.rb', line 5 def expected @expected end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/json5/errors.rb', line 5 def filename @filename end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
5 6 7 |
# File 'lib/json5/errors.rb', line 5 def line @line end |
#unexpected ⇒ Object (readonly)
Returns the value of attribute unexpected.
5 6 7 |
# File 'lib/json5/errors.rb', line 5 def unexpected @unexpected end |
Instance Method Details
#to_h ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/json5/errors.rb', line 23 def to_h { code: code, message: , filename: filename, byte_offset: byte_offset, end_byte_offset: end_byte_offset, line: line, column: column, unexpected: unexpected, expected: expected, excerpt: excerpt } end |
#with_context(filename: self.filename, byte_offset: self.byte_offset, end_byte_offset: self.end_byte_offset, line: self.line, column: self.column, excerpt: self.excerpt) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/json5/errors.rb', line 38 def with_context(filename: self.filename, byte_offset: self.byte_offset, end_byte_offset: self.end_byte_offset, line: self.line, column: self.column, excerpt: self.excerpt) return self if self.byte_offset && self.end_byte_offset && self.line && self.column && self.excerpt enriched = self.class.new( , code: code, filename: filename, byte_offset: byte_offset, end_byte_offset: end_byte_offset, line: line, column: column, unexpected: unexpected, expected: expected, excerpt: excerpt ) enriched.set_backtrace(backtrace) if backtrace enriched end |