module Eeml # Exception classes used by the EEML gem. module Exceptions #-- # TODO: have these inherit from a base parser error #++ # Eeml being parsed was valid XML, but bad EEML. class BadEeml < StandardError attr_accessor :line_num, :node_name #no guarantees either is available def to_s extras = [] extras << " node name: '" + node_name + "'" if node_name extras << " line_num: #{line_num}" if line_num super.to_s + extras.join(',') end end # Eeml being parsed was bad XML. class BadXML < StandardError; end class DataMissingValue < BadEeml; end class DataHasMultipleUnits < BadEeml; end class DataHasMultipleValues < BadEeml; end class NoDataStreams < BadEeml; end class DuplicateDataStreams < BadEeml; end class MissingNamespace < BadEeml; end #A structured exception which holds info about what was missing and from where. #Note: Some reasons we don't just hold everything in an unstructured exception message: #1. some bits might be useful for dev but not for the public, #2. testing is simplified by having the missing node name recorded explicitly (rather than in a human-readable, changeable string). class MissingNode < BadEeml attr_accessor :base_node_name, :sought_description, :sought_xpath def initialize(base_node_name, sought_description, sought_xpath = nil) @base_node_name = base_node_name @sought_description = sought_description @sought_xpath = sought_xpath end def to_s "Missing '#@sought_description' node from base node: '#@base_node_name'" + (@sought_xpath ? "with xpath: '#@sought_xpath'" : "") end end class MissingAttribute < BadEeml attr_accessor :node_name, :attribute_name def initialize(node_name, attribute_name) @node_name = node_name @attribute_name = attribute_name end def to_s "Missing attribute '#@attribute_name' from node '#@node_name'" end end class BadVersion < StandardError; end end end