alpine: Error context is lost
This is Alpine v2.7.0.
If I do something like this:
<template x-for="item in thisdoesnotexist" :key="item">
<div></div>
</template>
I get this not very useful error in the console:
[Error] TypeError: undefined is not an object (evaluating 'items.forEach')
(anonymous function) (alpine.js:1762)
In non-trivial setups, guessing where the faulty template code is, is extremely hard.
I remember in a not-so-distant Alpine version that I saw some more context (as in: the actual script string that failed to evaluate).
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 25 (18 by maintainers)
So, the current API is
throw error
which I think is fine and dandy and what most people expect.I would, however, not consider the error value thrown to be part of the “API spec” (esp. since it’s untyped), so adding some more context (e.g. the start element name and attributes) and then revise that later with some more/other info would be a good thing.
I have some experience building development tools and one of the “lessons learned” from this is that the quality of error messages thrown is extremely important, especially for non-expert users.
And the current situation in AlpineJS is, not great, and what I would consider a defect/bug. “There was an error somewhere about something” is what we get out of it.
Yeah, for that we should change
throw error;
tothrow errorMaker(baseerror, el, …)
or something.FWIW, when I wrote #447, I mentioned that we might want an Alpine.onerror handler, but I think delaying that decision was the right call because it was worth waiting for the right API instead of just doing the first one that came to mind.
Shouldn’t it be outerHTML?