class Trakerr::EventTraceBuilder
Public Class Methods
Gets the stactrace from the exception instance passed in. RETURNS: A Stacktrace
object that contains the trace of the exception passed in. exc:Exception: The exception caught or rescued.
# File trakerr/lib/event_trace_builder.rb, line 30 def self.get_stacktrace(exc) raise ArgumentError, "get_stacktrace expects an exception instance." unless exc.is_a? Exception strace = Trakerr::Stacktrace.new add_stack_trace(strace, exc) return strace end
Private Class Methods
Adds a InnerStackTrace
to the Stacktrace
object (which is a collection) strace:Stacktrace: The Stacktrace
object to append the latest InnerStackTrace
to. exc:Exception: The exception caught or rescued.
# File trakerr/lib/event_trace_builder.rb, line 45 def self.add_stack_trace(strace, exc) raise ArgumentError, "add_stack_trace did not get passed in the correct arguments" unless exc.is_a? Exception and strace.instance_of? Stacktrace newtrace = Trakerr::InnerStackTrace.new newtrace.type = exc.class.name newtrace.message = exc.message newtrace.trace_lines = get_event_tracelines(best_regexp_for(exc), exc.backtrace) strace.push(newtrace) end
# File trakerr/lib/event_trace_builder.rb, line 92 def self.best_regexp_for(exc) #add error check if defined?(Java::JavaLang::Throwable) && exc.is_a?(Java::JavaLang::Throwable) @@JAVA elsif defined?(OCIError) && exc.is_a?(OCIError) @@OCI #elsif execjs_exception?(exception) # Patterns::EXECJS disabled pending more complex test else @@RUBY end end
Formats and returns a StackTraceLines
object that holds the current stacktrace from the error. RETURNS: A StackTraceLines
object that contains the parsed traceback. regex:RegularExpression: The regular expression to parse the stacktrace text with. errarray:String[]: An array of strings which each of which is a StackTrace string line.
# File trakerr/lib/event_trace_builder.rb, line 62 def self.get_event_tracelines(regex, errarray) raise ArgumentError, "errarray should be an iterable object." unless errarray.respond_to?('each') stlines = Trakerr::StackTraceLines.new errarray.each {|line| stline = Trakerr::StackTraceLine.new match = parse_stacktrace(regex, line) stline.file, stline.line, stline.function = match[:file], match[:line], match[:function] stlines.push(stline) } return stlines end
Parses each given line by the regex RETURNS: A match object with the capture groups file function and line set. regex:RegularExpression: The regular expression to parse the stacktrace text with. line:String: A string with the traceline to parce
# File trakerr/lib/event_trace_builder.rb, line 83 def self.parse_stacktrace(regex, line) raise ArgumentError, "line should be a string." unless line.is_a? String match = regex.match(line) return match if match raise RegexpError, "line does not fit any of the supported stacktraces." #TODO: Error handle this? end