Open littledan opened 5 years ago
Playing around with elm style errors again.. just to see what they might look like:
TypeError: z.a.b.c is undefined.
--> components/some.js:511:26
511 | z.a.b.c.d
| ^^^
| |
| Property 'c' is undefined. Cannot access property 'd'.
Another example related to this...
class Calculator {
constructor() {
this.value = 0;
}
add(number) {
this.value += number;
}
subtract(number) {
this.value -= number;
return this;
}
};
let cal = new Calculator();
cal.subtract(3).add(5).add(2);
This code, which forgets to return this
from the add
method, gives you the following error:
TypeError: Cannot read property 'add' of undefined
I really like the Elm style pointers that tell you exactly there something is undefined, but in this case, when a method is returning undefined, it would be nice to be even more explicit and say something like The add() method of cal is returning undefined
.
I know that's probably a long shot, but A GIRL CAN DREAM.
I feel like the spidermonkey message is incomplete. I read that 4 times before I realized it was only talking about 'c' instead of 'd'. While it's correctly identifying the root problem, it doesn't mention the symptom at all and that seems surprising.
I suggest:
"TypeError: z.a.b.c.d could not be evaluated because z.a.b.c is undefined."
What is the code triggering the message?
What went wrong in the code? What is the system trying to tell you?
That
z.a.b.c
isundefined
, so you can't access thed
property on itWhat error message do you see? Which JavaScript environment produced this error?
eshost shows that only SpiderMonkey gives helpful output
What error message would you like to see?
SpiderMonkey-style output in all JS engines
Do you agree to license your suggested error message under an MIT-style license?
Yes