Class: ErrorToCommunicate::Heuristic::LoadError
Instance Attribute Summary
#einfo, #project
Class Method Summary
collapse
Instance Method Summary
collapse
#backtrace, #classname, #explanation, #initialize, #message, #semantic_backtrace, #semantic_explanation, #semantic_summary
Class Method Details
.for?(einfo) ⇒ 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_lib ⇒ Object
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_line ⇒ Object
41
42
43
|
# File 'lib/error_to_communicate/heuristic/load_error.rb', line 41
def first_nongem_line
relevant_backtrace.first
end
|
#path ⇒ Object
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_locations ⇒ Object
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_info ⇒ Object
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
[:context, "Couldn\'t find anything interesting ¯\\_(ツ)_/¯\n"]
end
[:heuristic, heuristic]
end
|