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

Improve error logs to help locating the issue in the HTL template #16

Open
kptdobe opened this issue Jul 10, 2018 · 2 comments
Open

Improve error logs to help locating the issue in the HTL template #16

kptdobe opened this issue Jul 10, 2018 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@kptdobe
Copy link
Contributor

kptdobe commented Jul 10, 2018

When there is something wrong in the htl template (like trying to access it.dummy.property which does not exist for exampl), the error log you get in the whole Petridish setup (and probably the same in the production setup) is something like:

[hlx] error: Error while rendering the resource: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at lengthOf (../project-helix/modules/helix-helpx/.hlx/build/html.js:295:53)
    at ../project-helix/modules/helix-helpx/.hlx/build/html.js:442:28
    at Generator.next (<anonymous>)
    at onFulfilled (../project-helix/modules/helix-helpx/node_modules/co/index.js:65:19)
    at ../project-helix/modules/helix-helpx/node_modules/co/index.js:54:5
    at new Promise (<anonymous>)
    at co (../project-helix/modules/helix-helpx/node_modules/co/index.js:50:10)
    at Runtime.run (../project-helix/modules/helix-helpx/node_modules/@adobe/htlengine/src/runtime/Runtime.js:47:12)
    at run (../project-helix/modules/helix-helpx/.hlx/build/html.js:305:20)
    at main (../project-helix/modules/helix-helpx/.hlx/build/html.js:482:12)
    at getContextPath.catch.then (../project-helix/modules/helix-helpx/.hlx/build/html.js:240:19)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)

Which gives not hint on what is wrong in the template. It is crucial for development to output a meaningful error that helps locating the issue.

@kptdobe kptdobe changed the title Improve error logs Improve error logs to help locating the issue in the HTL template Jul 10, 2018
@trieloff
Copy link
Contributor

I think there are two issues here:

  1. htlengine should handle missing properties more gracefully
  2. htlengine could really benefit from getting access to the logger and making use of it

@trieloff trieloff added the enhancement New feature or request label Jul 10, 2018
@ThaNarie
Copy link

ThaNarie commented Dec 4, 2018

The error from the fist comment is from:

return Array.isArray(c) ? c.length : Object.keys(c).length;

Adding something like if (!c) return 0; would already nicely address the issue. (what I've done by using withCodeTemplate and a custom template with that fix). But some more proper checks would be better.

Is this Issue also related to parser errors (since the points in the above comments talk about the rendering phase, although the Title is not specific about them) ?

Currently parsing errors throw an error:

throw new Error(`Error: ${msg}`);

However, there is not a lot of context (the line numbers are from the input string, not the complete file), so finding the issue based on the outputted characters is very hard.

line 1:10 token recognition error at: '/'

Adding console.log(offendingSymbol.source[1].strdata) to the output before throwing would at least show the parser input, and using the line and column info you could isolate the correct line, and add ^^^^ characters to point to the right column:

${foo.bar</p>
          ^

And/or include some more information in the Error that is thrown, so others could do something similar.

I hope this helps! :)

@tripodsan tripodsan added this to the Storybook AEM milestone Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants