instance method
ErrorHighlight::CoreExt#generate_snippet
generate_snippet
lib/error_highlight/core_ext.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/error_highlight/core_ext.rb, line 5
def generate_snippet
if ArgumentError === self && message =~ /\A(?:wrong number of arguments|missing keyword[s]?|unknown keyword[s]?|no keywords accepted)\b/
locs = self.backtrace_locations
return "" if locs.size < 2
callee_loc, caller_loc = locs
callee_spot = ErrorHighlight.spot(self, backtrace_location: callee_loc, point_type: :name)
caller_spot = ErrorHighlight.spot(self, backtrace_location: caller_loc, point_type: :name)
if caller_spot && callee_spot &&
caller_loc.path == callee_loc.path &&
caller_loc.lineno == callee_loc.lineno &&
caller_spot == callee_spot
callee_loc = callee_spot = nil
end
ret = +"\n"
[["caller", caller_loc, caller_spot], ["callee", callee_loc, callee_spot]].each do |header, loc, spot|
out = nil
if loc
out = " #{ header }: #{ loc.path }:#{ loc.lineno }"
if spot
_, _, snippet, highlight = ErrorHighlight.formatter.message_for(spot).lines
out += "\n | #{ snippet } #{ highlight }"
else
# do nothing
end
end
ret << "\n" + out if out
end
ret
else
spot = ErrorHighlight.spot(self)
return "" unless spot
return ErrorHighlight.formatter.message_for(spot)
end
end
No documentation available