Exception: MultiJSON::ParseError
- Inherits:
-
StandardError
- Object
- StandardError
- MultiJSON::ParseError
- Defined in:
- lib/multi_json/parse_error.rb
Overview
Raised when JSON parsing fails
Wraps the underlying adapter’s parse error with the original input data, plus best-effort line and column extraction from the adapter’s error message. Line/column are populated for adapters that include them in their messages (Oj, the json gem) and remain nil for adapters that don’t (Yajl, fast_jsonparser).
Instance Attribute Summary collapse
-
#column ⇒ Integer?
readonly
The 1-based column reported by the adapter.
-
#data ⇒ String?
readonly
The input string that failed to parse.
-
#line ⇒ Integer?
readonly
The 1-based line number reported by the adapter.
Class Method Summary collapse
-
.build(original_exception, data) ⇒ ParseError
Build a ParseError from an original exception.
Instance Method Summary collapse
-
#initialize(message = nil, data: nil, cause: nil) ⇒ ParseError
constructor
Create a new ParseError.
Constructor Details
#initialize(message = nil, data: nil, cause: nil) ⇒ ParseError
Create a new ParseError
57 58 59 60 61 62 63 64 |
# File 'lib/multi_json/parse_error.rb', line 57 def initialize( = nil, data: nil, cause: nil) super() @data = data match = location_match() @line = match && Integer(match[1]) @column = match && match[2] && Integer(match[2]) set_backtrace(cause.backtrace) if cause end |
Instance Attribute Details
#column ⇒ Integer? (readonly)
The 1-based column reported by the adapter
46 47 48 |
# File 'lib/multi_json/parse_error.rb', line 46 def column @column end |
#data ⇒ String? (readonly)
The input string that failed to parse
28 29 30 |
# File 'lib/multi_json/parse_error.rb', line 28 def data @data end |
#line ⇒ Integer? (readonly)
The 1-based line number reported by the adapter
37 38 39 |
# File 'lib/multi_json/parse_error.rb', line 37 def line @line end |
Class Method Details
.build(original_exception, data) ⇒ ParseError
Build a ParseError from an original exception
74 75 76 |
# File 'lib/multi_json/parse_error.rb', line 74 def self.build(original_exception, data) new(original_exception., data: data, cause: original_exception) end |