File: parseexception.rb

package info (click to toggle)
librexml-ruby 1.2.5-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 792 kB
  • ctags: 655
  • sloc: ruby: 3,778; xml: 1,609; java: 109; makefile: 43
file content (47 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module REXML
	class ParseException < Exception
		attr_accessor :source, :element, :continued_exception

		def initialize( message, source=nil, element=nil, exception=nil )
			super(message)
			@source = source
			@element = element
			@continued_exception = exception
		end

		def to_s
			# Quote the original exception, if there was one
			if @continued_exception
				err = @continued_exception.message
				err << "\n"
				err << @continued_exception.backtrace[0..3].join("\n")
				err << "\n...\n"
			else
				err = ""
			end

			# Get the stack trace and error message
			err << super

			# Add contextual information
			err << "\nat about line #{@source.current_line}:\n#{@source.buffer[0..80].gsub(/\n/, ' ')}\n" if @source
			# Information about the path of the element the error occurred in
			if @element
				path = @element.expanded_name
				path = "TAG MISSING ERROR" unless path
				parent = @element.parent
				while parent and not parent.type == "Document"
					path = parent.expanded_name + "/" + path
					parent = parent.parent
				end
				err << "in element #{path}\n"
			end
			#err << @continued_exception.message if @continued_exception
			err
		end

		def line
			@source.current_line if @source
		end
	end	
end