Skip to content
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

Invalid template results can cause cryptic errors. #68

Closed
theengineear opened this issue Dec 9, 2020 · 0 comments · Fixed by #69
Closed

Invalid template results can cause cryptic errors. #68

theengineear opened this issue Dec 9, 2020 · 0 comments · Fixed by #69

Comments

@theengineear
Copy link
Collaborator

A template result can successfully be created and then fail to render. Because it's common that an element will only override the "template" method, the stack trace will not actually print the name of the problematic file — this makes debugging incredibly difficult.

One approach would be to wrap the call to lit-html's render in a try-catch such that we can append DOM pathing information when we encounter an error.

Example cryptic stack trace:

Uncaught TypeError: items is not iterable
    at repeat.ts:122
    at NodePart.commit (parts.ts:210)
    at TemplateInstance.update (template-instance.ts:53)
    at NodePart.__commitTemplateResult (parts.ts:280)
    at NodePart.commit (parts.ts:221)
    at render (render.ts:55)
    at HTMLElement.render (x-element.js:158)
    at Function.__updateHost (x-element.js:838)
    at Function.__initializeHost (x-element.js:742)
    at HTMLElement.connectedCallback (x-element.js:131)

But we could modify the message to be:

Uncaught TypeError: items is not iterable — Invalid template for "HelloElement" at path "hello-world < div#container"
    at repeat.ts:122
    at NodePart.commit (parts.ts:210)
    at TemplateInstance.update (template-instance.ts:53)
    at NodePart.__commitTemplateResult (parts.ts:280)
    at NodePart.commit (parts.ts:221)
    at render (render.ts:55)
    at HTMLElement.render (x-element.js:158)
    at Function.__updateHost (x-element.js:837)
    at Function.__initializeHost (x-element.js:741)
    at HTMLElement.connectedCallback (x-element.js:131)

In the later case, you immediately know where to start debugging. You may not know why items is not iterable, but at least you know where to look for the culprit.

theengineear added a commit that referenced this issue Dec 9, 2020
This closes #68, closes #67, closes #66, closes #57, closes #46,
closes #42, closes #36, closes #31, closes #30, closes #28, closes #26,
and closes #25.
theengineear added a commit that referenced this issue Dec 9, 2020
This closes #68, closes #67, closes #66, closes #57, closes #46,
closes #42, closes #36, closes #31, closes #30, closes #28, closes #26,
and closes #25.
theengineear added a commit that referenced this issue Dec 9, 2020
This closes #68, closes #67, closes #66, closes #57, closes #46,
closes #42, closes #36, closes #31, closes #30, closes #28, closes #26,
and closes #25.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant