-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Silent failure when referencing an attribute of non-existent object in a tag #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It looks like this silent failure is only affecting the REPL. The code that the compiler is generating does actually throw an exception at runtime - while trying to evaluate I'm not sure whether something like this particular issue would fall under the eventual more-rigorous compile-time checks. Either way, there will still always be runtime errors that the compiler can't foresee. In your own code, you can handle this however you want - but it's not entirely clear to me what a nice, general way to display arbitrary errors in the REPL UI would be. Perhaps for now the REPL could be edit - Ah, in fact, the REPL is already doing pretty much exactly this for errors that arise from attempting to update the data for an existing component - here. I would think that same approach could be used for errors that arise during the instantiation of the component as well. |
Thanks @Conduitry for the reply. One thing I wonder about is in regard to localizing the effects of a failure. For example, assuming there is a variable "name" but not "example" what would happen is that none of the component below would render even though part of the component could resolve successfully: <h2>I might think this should show up since there would be no error here {{ name }} </h2>
<h1>Hello {{ example.fake }}</h1>
<h2>this also wont show up {{ name }} </h2> Looking at what gets compiled:
I wonder if isolating the creation of elements with variables resolved at runtime like |
Thanks, I've opened sveltejs/v2.svelte.dev#39 — the REPL should indeed give more useful feedback. As far as localising errors goes, I reckon that should fall under development warnings — the cost of always checking that objects exist before accessing their properties is too high to always do it, I think. |
We can close this now, as the REPL gives much better feedback — it reports the error, and uses sourcemaps to figure out which character to highlight in the editor: |
Noticed that if I accidentally reference {{ foo.bar }} without having foo declared there is no error message but I just get a blank screen.
Reproduced here: https://svelte.technology/repl/?version=1.6.5&gist=96eac2057376cf37f092145e4b22fcc6
The text was updated successfully, but these errors were encountered: