module Airbrake::Backtrace

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/airbrake-ruby/backtrace.rbs

module Airbrake::Backtrace
  def self.java_exception?: (StandardError exception) -> untyped
  def self.parse: (StandardError exception) -> untyped
  def best_regexp_for: (StandardError exception) -> Regexp
  def execjs_exception?: (StandardError exception) -> false
  def frame_in_root?: (Hash frame, String root_directory) -> untyped
  def match_frame: (Regexp regexp, String stackframe) -> untyped
  def oci_exception?: (StandardError exception) -> untyped
  def parse_backtrace: (StandardError exception) -> untyped
  def stack_frame: (Regexp regexp, String stackframe) -> untyped
end

def self.java_exception?(exception)

Experimental RBS support (using type sampling data from the type_fusion project).

def self.java_exception?: (StandardError exception) -> untyped

This signature was generated using 7 samples from 1 application.

Returns:
  • (Boolean) -

Parameters:
  • exception (Exception) --
def self.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

def self.parse(exception)

Experimental RBS support (using type sampling data from the type_fusion project).

def self.parse: (StandardError exception) -> untyped

This signature was generated using 5 samples from 1 application.

Returns:
  • (ArrayString,Integer}>) - the parsed backtrace

Parameters:
  • exception (Exception) -- The exception, which contains a backtrace to
def self.parse(exception)
  return [] if exception.backtrace.nil? || exception.backtrace.none?
  parse_backtrace(exception)
end

def best_regexp_for(exception)

Experimental RBS support (using type sampling data from the type_fusion project).

def best_regexp_for: (StandardError exception) -> Regexp

This signature was generated using 8 samples from 1 application.

def best_regexp_for(exception)
  if java_exception?(exception)
    Patterns::JAVA
  elsif oci_exception?(exception)
    Patterns::OCI
  elsif execjs_exception?(exception)
    Patterns::EXECJS
  else
    Patterns::RUBY
  end
end

def execjs_exception?(exception)

Experimental RBS support (using type sampling data from the type_fusion project).

def execjs_exception?: (StandardError exception) -> false

This signature was generated using 7 samples from 1 application.

def execjs_exception?(exception)
  return false unless defined?(ExecJS::RuntimeError)
  return true if exception.is_a?(ExecJS::RuntimeError)
  return true if exception.cause && exception.cause.is_a?(ExecJS::RuntimeError)
  false
end

def frame_in_root?(frame, root_directory)

Experimental RBS support (using type sampling data from the type_fusion project).

def frame_in_root?: (file | String | line | Integer | function | String frame, String root_directory) -> untyped

This signature was generated using 4 samples from 1 application.

def frame_in_root?(frame, root_directory)
  frame[:file].start_with?(root_directory) && frame[:file] !~ %r{vendor/bundle}
end

def match_frame(regexp, stackframe)

Experimental RBS support (using type sampling data from the type_fusion project).

def match_frame: (Regexp regexp, String stackframe) -> untyped

This signature was generated using 5 samples from 1 application.

def match_frame(regexp, stackframe)
  match = regexp.match(stackframe)
  return match if match
  Patterns::GENERIC.match(stackframe)
end

def oci_exception?(exception)

Experimental RBS support (using type sampling data from the type_fusion project).

def oci_exception?: (StandardError exception) -> untyped

This signature was generated using 5 samples from 1 application.

def oci_exception?(exception)
  defined?(OCIError) && exception.is_a?(OCIError)
end

def parse_backtrace(exception)

Experimental RBS support (using type sampling data from the type_fusion project).

def parse_backtrace: (StandardError exception) -> untyped

This signature was generated using 2 samples from 1 application.

def parse_backtrace(exception)
  regexp = best_regexp_for(exception)
  root_directory = Airbrake::Config.instance.root_directory.to_s
  exception.backtrace.map.with_index do |stackframe, i|
    frame = stack_frame(regexp, stackframe)
    next(frame) if !Airbrake::Config.instance.code_hunks || frame[:file].nil?
    if !root_directory.empty?
      populate_code(frame) if frame_in_root?(frame, root_directory)
    elsif i < CODE_FRAME_LIMIT
      populate_code(frame)
    end
    frame
  end
end

def populate_code(frame)

def populate_code(frame)
  code = Airbrake::CodeHunk.new.get(frame[:file], frame[:line])
  frame[:code] = code if code
end

def stack_frame(regexp, stackframe)

Experimental RBS support (using type sampling data from the type_fusion project).

def stack_frame: (Regexp regexp, String stackframe) -> untyped

This signature was generated using 3 samples from 1 application.

def stack_frame(regexp, stackframe)
  if (match = match_frame(regexp, stackframe))
    return {
      file: match[:file],
      line: (Integer(match[:line]) if match[:line]),
      function: match[:function],
    }
  end
  logger.error(
    "can't parse '#{stackframe}' (please file an issue so we can fix " \
    "it: https://github.com/airbrake/airbrake-ruby/issues/new)",
  )
  { file: nil, line: nil, function: stackframe }
end