Closed Bug 1407903 Opened 7 years ago Closed 6 years ago

Say property name in error message when accessing property of undefined value

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

RESOLVED DUPLICATE of bug 1259822
Tracking Status
firefox58 --- fix-optional

People

(Reporter: arai, Unassigned)

References

(Blocks 1 open bug)

Details

Code:
  var obj = { foo() {} }; obj.foo(10).bar

Error message on Firefox:
  TypeError: obj.foo(...) is undefined

Error message on Chrome:
  TypeError: Cannot read property 'bar' of undefined

saying property name will make the error clearer.
not sure the best wording tho, something like:

  TypeError: obj.foo(...) is undefined and cannot read 'bar' property

or:

  TypeError: Cannot read property 'bar' of obj.foo(...) that is undefined

or something
I was the one confused on IRC (and the one arguably too dense to understand the error message for quite an embarrassing amount of time). Without opening Chrome and seeing its error I might've wasted even more time here. 

Background: My case was just _slightly_ different:

  foo=[1,2,3]; foo.find(x => x == 4).bar

Having had a couple issues with old IEs just a couple days ago I consistently misparsed this as 'find' being missing/being undefined. I made sure that foo is an array, I saw that find is available in the debugger and yet evaluating this lead to the error message above, which .. again I read as _find_ being undefined.

FWIW: I understand that you already _know_ that this is a function expression that returns undefined (because of the formatting of foo(...) in the error message). I guess it would've helped me a lot if this error would be tweaked from (taking my example)

  TypeError: foo.find(...) is undefined

to

  TypeError: Result of foo.find(...) is undefined

Including the property I tried to access might help as well, but this minor rephrasing would've solved my misunderstanding immediately.

Sorry for the nitpicking/fussing over something this simple.
Priority: -- → P3
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.