Class: ErrorToCommunicate::Heuristic::LoadError

Inherits:
ErrorToCommunicate::Heuristic show all
Defined in:
lib/error_to_communicate/heuristic/load_error.rb

Instance Attribute Summary

Attributes inherited from ErrorToCommunicate::Heuristic

#einfo, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ErrorToCommunicate::Heuristic

#backtrace, #classname, #explanation, #initialize, #message, #semantic_backtrace, #semantic_explanation, #semantic_summary

Constructor Details

This class inherits a constructor from ErrorToCommunicate::Heuristic

Class Method Details

.for?(einfo) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
# File 'lib/error_to_communicate/heuristic/load_error.rb', line 8

def self.for?(einfo)
  einfo.classname == 'LoadError' &&
    einfo.message.include?(' -- ')
end

Instance Method Details

#first_line_within_libObject



45
46
47
# File 'lib/error_to_communicate/heuristic/load_error.rb', line 45

def first_line_within_lib
  @first_line_within_lib ||= relevant_backtrace.find { |loc| loc.path.to_s.start_with? project.root }
end

#first_nongem_lineObject



41
42
43
# File 'lib/error_to_communicate/heuristic/load_error.rb', line 41

def first_nongem_line
  relevant_backtrace.first
end

#pathObject



13
14
15
# File 'lib/error_to_communicate/heuristic/load_error.rb', line 13

def path
  @path ||= Pathname.new message.split(' -- ', 2).last
end

#relevant_locationsObject



37
38
39
# File 'lib/error_to_communicate/heuristic/load_error.rb', line 37

def relevant_locations
  @relevant_locations ||= [first_nongem_line, first_line_within_lib].compact.uniq
end

#semantic_infoObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/error_to_communicate/heuristic/load_error.rb', line 17

def semantic_info
  heuristic = if relevant_locations.any?
    relevant_locations.map { |location|
      [:code, {
        location:  location,
        highlight: location.label,
        context:   -5..5,
        message:   "Couldn't find #{path.to_s.inspect}",
        emphasis:  :code,
      }]
    }
  else
    # The newline here implies the semantic analysis needs to get better,
    # it only does this b/c it should be a block-element, but isn't being sectioned like that, correctly
    [:context, "Couldn\'t find anything interesting ¯\\_(ツ)_/¯\n"]
  end

  [:heuristic, heuristic]
end