Exception: MultiXml::ParseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/multi_xml/errors.rb

Overview

Raised when XML parsing fails

Preserves the original XML and underlying cause for debugging.

Examples:

Catching a parse error

begin
  MultiXml.parse('<invalid>')
rescue MultiXml::ParseError => e
  puts e.xml   # The malformed XML
  puts e.cause # The underlying parser exception
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, xml: nil, cause: nil) ⇒ ParseError

Create a new ParseError

Examples:

Create a parse error

ParseError.new("Invalid XML", xml: "<bad>", cause: original_error)

Parameters:

  • message (String, nil) (defaults to: nil)

    Error message

  • xml (String, nil) (defaults to: nil)

    The original XML that failed to parse

  • cause (Exception, nil) (defaults to: nil)

    The underlying parser exception



40
41
42
43
44
# File 'lib/multi_xml/errors.rb', line 40

def initialize(message = nil, xml: nil, cause: nil)
  @xml = xml
  @cause = cause
  super(message)
end

Instance Attribute Details

#causeException? (readonly)

The underlying parser exception

Examples:

Access the cause

error.cause #=> #<Nokogiri::XML::SyntaxError: ...>

Returns:

  • (Exception, nil)

    the original exception from the parser



29
30
31
# File 'lib/multi_xml/errors.rb', line 29

def cause
  @cause
end

#xmlString? (readonly)

The original XML that failed to parse

Examples:

Access the failing XML

error.xml #=> "<invalid>"

Returns:

  • (String, nil)

    the XML string that caused the error



21
22
23
# File 'lib/multi_xml/errors.rb', line 21

def xml
  @xml
end