module StackTrace

Private Class Methods

best_regexp_for(exception) click to toggle source
# File lib/sqreen/kit/signals/stack_trace.rb, line 91
def best_regexp_for(exception)
  if java_exception?(exception)
    Patterns::JAVA
  else
    Patterns::RUBY
  end
end
do_parse(exception) click to toggle source
# File lib/sqreen/kit/signals/stack_trace.rb, line 83
def do_parse(exception)
  regexp = best_regexp_for(exception)

  exception.backtrace.map do |stackframe|
    stack_frame(regexp, stackframe)
  end
end
java_exception?(exception) click to toggle source

Checks whether the given exception was generated by JRuby's VM.

@param [Exception] exception @return [Boolean]

# File lib/sqreen/kit/signals/stack_trace.rb, line 103
def java_exception?(exception)
  if defined?(Java::JavaLang::Throwable) &&
     exception.is_a?(Java::JavaLang::Throwable)
    return true
  end

  return false unless exception.respond_to?(:backtrace)

  (Patterns::JAVA =~ exception.backtrace.first) != nil
end
match_frame(regexp, stackframe) click to toggle source
# File lib/sqreen/kit/signals/stack_trace.rb, line 139
def match_frame(regexp, stackframe)
  match = regexp.match(stackframe)
  return match if match

  Patterns::GENERIC.match(stackframe)
end
parse(exception) click to toggle source

Parses an exception's backtrace.

@param exception [Exception] The exception, which contains a backtrace to

parse

@return [Array<Hash{Symbol=>String,Integer}>] the parsed backtrace

# File lib/sqreen/kit/signals/stack_trace.rb, line 69
def parse(exception)
  return [] if exception.backtrace.nil? || exception.backtrace.none?
  do_parse(exception)
end
parse_backtrace(backtrace) click to toggle source
# File lib/sqreen/kit/signals/stack_trace.rb, line 74
def parse_backtrace(backtrace)
  # assume normal ruby backtrace
  backtrace.map do |stackframe|
    stack_frame(Patterns::RUBY, stackframe)
  end
end
sqreen_code?(abs_path) click to toggle source
# File lib/sqreen/kit/signals/stack_trace.rb, line 134
def sqreen_code?(abs_path)
  # Ruby uses / on Windows too
  abs_path.include?('/lib/sqreen/')
end
stack_frame(regexp, stackframe) click to toggle source
# File lib/sqreen/kit/signals/stack_trace.rb, line 114
def stack_frame(regexp, stackframe)
  if (match = match_frame(regexp, stackframe))
    return {
      in_app: sqreen_code?(match[:file]),
      abs_path: match[:file],
      function: match[:function],
      lineno: (Integer(match[:line]) if match[:line]),
    }
  end

  logger.error(
    "can't parse '#{stackframe}' (please file an issue so we can fix " \
        'it: https://github.com/sqreen/ruby-sdk/issues/new)',
  )
  {
    in_app: false,
    function: stackframe,
  }
end