Class: Steep::Diagnostic::Ruby::UnexpectedError

Inherits:
Base
  • Object
show all
Defined in:
lib/steep/diagnostic/ruby.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#location, #node

Instance Method Summary collapse

Methods inherited from Base

#diagnostic_code

Methods included from Helper

#error_name, #full_message

Constructor Details

#initialize(node:, error:) ⇒ UnexpectedError

Returns a new instance of UnexpectedError.



780
781
782
783
# File 'lib/steep/diagnostic/ruby.rb', line 780

def initialize(node:, error:)
  super(node: node)
  @error = error
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



778
779
780
# File 'lib/steep/diagnostic/ruby.rb', line 778

def error
  @error
end

Instance Method Details

#detail_linesObject



789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
# File 'lib/steep/diagnostic/ruby.rb', line 789

def detail_lines
  if trace = error.backtrace
    io = StringIO.new

    total = trace.size
    if total > 30
      trace = trace.take(15)
    end

    trace.each.with_index do |line, index|
      io.puts "#{index+1}. #{line}"
    end

    if trace.size != total
      io.puts "  (#{total - trace.size} more backtrace)"
    end

    io.string
  end
end

#header_lineObject



785
786
787
# File 'lib/steep/diagnostic/ruby.rb', line 785

def header_line
  "UnexpectedError: #{error.message}(#{error.class})"
end