WebReflection / hyperHTML

A Fast & Light Virtual DOM Alternative
ISC License
3.07k stars 112 forks source link

Suggestion: more meaningful error messages #207

Closed Fredx87 closed 6 years ago

Fredx87 commented 6 years ago

When there is an error in the syntax of the template or the interpolated values, the exception raised by the library is not very helpful to understand where is the error.

I have two example, but probably there a lot more possibilities.

When using partial attributes, the exception raised is: this[(t - 1)] is not a function https://codepen.io/anon/pen/EQzdpp?editors=0011

When there is an error using the map function (for example forgetting to return the wired content), the exception raised is: TypeError: cannot use 'in' operator to search for 'ELEMENT_NODE' in 't' https://codepen.io/anon/pen/EQzdpp?editors=0011

I think that raise more meaningful excpetions (for example "Error: partial attributes are not supported" for the first one) could be very useful

albertosantini commented 6 years ago

There are a few issues about this topic, for instance https://github.com/WebReflection/hyperHTML/issues/192 and others.

Basically it is a trade-off between speed and abstraction.

WebReflection commented 6 years ago

Hi @Fredx87, as mentioned by @albertosantini there are no ways I can improve broken syntax, same way if you write bad JS you have just "unexpected this or that in here".

If you read through other issues, you'll notice this quote of mine:

However, the rare times it happened to me (it's something everyone at the beginning will crash into then once you get how to write valid HTML with hyperHTML you won't see this error ever again) it was instantly easy to spot my template had errors.

The solution is to have a hyperhtml.dev.js and a hyperhtml.js but I'm still trying to think how to do that in a clean way and without going mental with tooling, build around RegExp, and similar stuff.

The library is growing and going beyond 5K to add try catches and a debug flag doesn't seem the right approach.

As mentioned in other threads, this is a won't fix for now, but I'm sure once you'll remember the few rules beyond hyperHTML (e.g. no partial attributes which is well documented) you'll be just fine.

Sorry if this wasn't the answer you were expecting.