Open Bug 1257918 Opened 8 years ago Updated 2 years ago

Error in Web Console reports the wrong line number

Categories

(DevTools :: Console, defect, P2)

47 Branch
defect

Tracking

(Not tracked)

People

(Reporter: peterbe, Unassigned)

References

()

Details

Attachments

(1 file)

I wrote this code: https://gist.github.com/peterbe/8ff51943f3f62441fffe

There's an interval callback that executes function `checkStatus`. And if that one fails (it does an ajax promise thing), it cancels the interval. 

But there's a bug in my code. The bug is that the `checkStatus()` function didn't return the promise. I.e. the `.fail(...)` would be executed on the output of `checkStatus()` which is, I believe, undefined. 

The real problem is the error message::

 TypeError: checkStatus(...) is undefined

I had to use Chrome to understand my mistake. I thought I had misspelled "checkStatus" and triple-checked that. And I had to check the scoping rules but as you can see, they should be in the same scope. 

The error message Chrome gives is better::

 Uncaught TypeError: Cannot read property 'fail' of undefined

In Firefox, it said the error was on line 14. In Chrome it was on line 15.
Open this in Firefox and open your web console. It complains about checkStatus() and not about my AFTER-use of the result of checkStatus().
http://codepen.io/peterbe/pen/yOgrdm?editors=0011
Moving this to the console component.
Component: Developer Tools: Debugger → Developer Tools: Console
Attached file error-message.html
Reduced test case
Morgan, this seems semi-related to to JS error message work you are doing.

If you open: https://bug1257918.bmoattachments.org/attachment.cgi?id=8734759:

The error we are emitting is `TypeError: checkStatus(...) is undefined` (line 6).
And here's what Chrome is emitting: `Uncaught TypeError: Cannot read property 'fail' of undefined` (line 7)

I think pointing to line 7 in this case is more useful, since the call to checkStatus() didn't throw but rather the error is happening once trying to call fail().  Also including the name of the function it was trying to call (`fail`) is useful.  Without deciding on exact wording, do you think we'd be able to modify the message to include these things (the updated line number and the name of the property it was trying to access)?
Flags: needinfo?(winter2718)
(In reply to Brian Grinstead [:bgrins] from comment #4)
> Morgan, this seems semi-related to to JS error message work you are doing.
> 
> If you open: https://bug1257918.bmoattachments.org/attachment.cgi?id=8734759:
> 
> The error we are emitting is `TypeError: checkStatus(...) is undefined`
> (line 6).
> And here's what Chrome is emitting: `Uncaught TypeError: Cannot read
> property 'fail' of undefined` (line 7)
> 
> I think pointing to line 7 in this case is more useful, since the call to
> checkStatus() didn't throw but rather the error is happening once trying to
> call fail().  Also including the name of the function it was trying to call
> (`fail`) is useful.  Without deciding on exact wording, do you think we'd be
> able to modify the message to include these things (the updated line number
> and the name of the property it was trying to access)?

I agree that we can and should improve the error message for attempted property access of undefined. I'll create another bug.
Flags: needinfo?(winter2718)
Depends on: 1259822
Second that. I have a similar case here:
Firefox - "TypeError: e is undefined"
Chrome - "Uncaught TypeError: Cannot set property 'amplify' of undefined"
Btw, I minified my JS when getting this error also running it through babel. If I switch Babel off, it gets even less meaningful:
"TypeError: (intermediate value)(...) is not a function" 
Still the same msg in Chrome as above
Sorry for the bug spam, in the second example JS seems to have been cached in Chrome. Without Babel it actually gives the same error as Firefox "Uncaught TypeError: (intermediate value)(...) is not a function"
can't delete my previous comment, #7 and #8 could be hidden I guess
Product: Firefox → DevTools
Priority: -- → P2
The error message is now "TypeError: checkStatus(...) is undefined; can't access its "fail" property" which I think solve one part of the issue.
Let's keep this bug for the line number.
Summary: Confusing TypeError error in Web Console → Error in Web Console reports the wrong line number
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: