Skip to content

Call to ErrorHighlight::spot returns partial data for some exceptions #58

@sdcorey

Description

@sdcorey

Configuration

ruby 3.3.3

Steps to Reproduce

Run the following script error_script.rb:

begin
  x = nil
  x += 5
rescue StandardError => exception
  pp ErrorHighlight.spot(exception, backtrace_location: exception.backtrace_locations[0])
end

using

ruby error_script.rb

Expected Results

My reading of the comment in the header above the ErrorHighlight::spot method is that if its return value is not nil, it should be a hash containing, among other things, integer values corresponding to the :first_lineno and :last_lineno keys.

Actual Results

ErrorHighlight::spot returns a hash in which the values corresponding to the :first_lineno and :last_lineno keys are nil.

Analysis

The above program eventually finds itself in the last elsif clause of ErrorHighlight::Spotter#spot_call_for_name. That clause doesn't set the @beg_lineno and @end_lineno instance variables, whereas all the other clauses in that statement do. Eventually these variable values find their way into the return value of ErrorHighlight::Spotter#spot as nils.

I noticed it because it causes rails exception reporting code to malfunction in certain circumstances. #54384

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions