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
Add line number and a snippet of the source template to template render error reports #10966
Comments
I don't think this will be technically possible for current Vue 2 but the source maps in Vue 3 does already allow breaking in the middle of the template so I think it might be possible to have this. @znck do you happen to know more? |
You can write a custom directive but let me try it and confirm. |
I wasn't aware of the source map support in Vue 3 - that's some good news! Looks like this might be useful in that scenario: https://www.stacktracejs.com/#!/docs/stacktrace-gps It appears to load and parse a source map and convert a stack trace frame to a location in the context of the source map. It also has an MIT license and isn't a lot of code so it could be readily adapted and integrated. |
I vote for this proposal as well |
This is a great idea, I don't know how people debug templates with hundreds of lines today. |
@posva has there been any action on this in Vue 3? If not, I may have the cycles to put together a PR for it. |
What problem does this feature solve?
It helps developers pinpoint template errors in larger templates.
At the moment, render errors look like this (from version 2.5.18):
While
TypeError: Cannot read property 'name' of undefined
and the template it occurred in is of course quite useful information it could be better if there are many references to 'name' in<ASelectDate>
and the exact location of the error is not obvious. I'm proposing a feature enhancement that would include a line number relative to the template itself (assuming it is not just a render function) and also output the line before, the line of the error and the line following it from the source template to provide context information to the developer.I believe this can be achieved using the same techniques that are used in compilers when debugging information is enabled and generated. In development mode, as a template is compiled, context information is maintained (line numbers and the source lines of the template) and as each piece is compiled and converted into render function code this information is captured as "debugging symbols" (using compiler terms). If this debugging information is available when a render error occurs, the stack trace is examined and used with the debugging information to determine the line number and template lines to display with the warning.
The result would be an error report that looks something like:
What does the proposed API look like?
In terms of implementation details, this feature would be enabled in development mode. The debugging information would be generated during template compilation and could be attached to the render function itself when compiled and emitted so that no additional files need to be produced, packaged or loaded. If the debugging information is available, the error message as envisioned above is produced. If not, the current style of warning is emitted instead along with a message that says for better details, reproduce the error in development mode.
The text was updated successfully, but these errors were encountered: