Sha256: a1ed34a476ceb30eaea5d192638e37b95a3f05f101553822175585804345ffe4

Contents?: true

Size: 1.98 KB

Versions: 21

Compression:

Stored size: 1.98 KB

Contents

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 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 
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
eeml-0.0.29 lib/eeml/exceptions.rb
eeml-0.0.25 lib/eeml/exceptions.rb
eeml-0.0.24 lib/eeml/exceptions.rb
eeml-0.0.23 lib/eeml/exceptions.rb
eeml-0.0.22 lib/eeml/exceptions.rb
eeml-0.0.21 lib/eeml/exceptions.rb
eeml-0.0.18 lib/eeml/exceptions.rb
eeml-0.0.17 lib/eeml/exceptions.rb
eeml-0.0.14 lib/eeml/exceptions.rb
eeml-0.0.13 lib/eeml/exceptions.rb
eeml-0.0.12 lib/eeml/exceptions.rb
eeml-0.0.11 lib/eeml/exceptions.rb
eeml-0.0.10 lib/eeml/exceptions.rb
eeml-0.0.9 lib/eeml/exceptions.rb
eeml-0.0.8 lib/eeml/exceptions.rb
eeml-0.0.7 lib/eeml/exceptions.rb
eeml-0.0.6 lib/eeml/exceptions.rb
eeml-0.0.3 lib/eeml/exceptions.rb
eeml-0.0.4 lib/eeml/exceptions.rb
eeml-0.0.5 lib/eeml/exceptions.rb