canjs / can-view-scope

Scope management for view engines
https://canjs.com/doc/can-view-scope.html
MIT License
4 stars 0 forks source link

Improve the “unable to find key” warning #206

Closed chasenlehara closed 5 years ago

chasenlehara commented 5 years ago

This example: https://codepen.io/anon/pen/zVXJzr?editors=0011

…produces this warning in the console: MyAppView:2: Unable to find key "someList.length".

The reason is that there’s a return in the getter that causes someList to be set to a Promise before it’s resolved with a different value.

The error is ok, but I think it would be better if it logged the value of the last property it can read, in this case someList. I think that would make it easier to see what someList is and why it doesn’t have a length property:

MyAppView:2: Unable to find key "someList.length". Found "someList" with value: %o

The %o would be replaced with the someList value.

Here’s an example of this type of error in can-bind: https://github.com/canjs/can-bind/blob/c010f16182b20ebfd0503422bc23230e9b3c5f20/can-bind.js#L531-L537

Here’s where the error is generated in this project: https://github.com/canjs/can-view-scope/blob/742532a35da4f88afefdbd00543095b047ea4112/scope-key-data.js#L77-L117

P.S. Can we remove the extra \n here? https://github.com/canjs/can-view-scope/blob/742532a35da4f88afefdbd00543095b047ea4112/scope-key-data.js#L111