-
Notifications
You must be signed in to change notification settings - Fork 172
Fix template error line numbers #380
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
Conversation
new HashMap<>()); | ||
|
||
assertThat(result.getErrors()).hasSize(1); | ||
assertThat(result.getErrors().get(0).getLineno()).isEqualTo(7); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously this would be on line number 4 of base.html
highlighting {% set test = 1 + 1 %}
as the error rather than {{ "test"|add(1) }}
in the included file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for tackling this. 🎉
@@ -498,6 +498,13 @@ public int getPosition() { | |||
} | |||
|
|||
public void addError(TemplateError templateError) { | |||
|
|||
// fix line numbers not matching up with source template | |||
if (!context.getCurrentPathStack().isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is needed for addAllErrors
as well. I'm also wary of any place that might be doing getErrors().add()
instead of this method.
To break down how this works:
|
I am also planning on wrapping the error messages to be clear where the error in the other file occurs. |
Currently the wrapped error messages look like: |
@mattcoley This looks good. Trying to think of odd edge cases where this is not going to be ideal, but can't think of any. Minor convenience suggestion. In design manager error output would be cool if the path text linked to the file/open tab in the design manager. |
We can add a path attribute to the error message so that the DM can link to the other file. |
… path off of stack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a bunch of changes to try and address more problems here, particularly around importing, macros, and resolving blocks / extend parents. I added more test cases as well. Let me know what you think.
@@ -75,4 +77,30 @@ public void push(String path, int lineNumber, int startPosition) { | |||
|
|||
return Optional.of(stack.peek()); | |||
} | |||
|
|||
public int getTopLineNumber() { | |||
if (topLineNumber == -1 && parent != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added parent stack checks for these new methods. This will help us deal with child interpreters and also is more consistent with the other methods on CallStack
.
Node parentRoot = extendParentRoots.removeFirst(); | ||
output = new OutputList(config.getMaxOutputSize()); | ||
|
||
for (Node node : parentRoot.getChildren()) { | ||
lineNumber = node.getLineNumber() - 1; // The line number is off by one when rendering the extend parent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to reorient the interpreter when processing extend parents, since this happens after normal rendering.
@@ -309,10 +313,14 @@ private void resolveBlockStubs(OutputList output, Stack<String> blockNames) { | |||
OutputList blockValueBuilder = new OutputList(config.getMaxOutputSize()); | |||
|
|||
for (Node child : block.getNodes()) { | |||
lineNumber = child.getLineNumber(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to reorient the interpreter when resolving blocks.
|
||
try (InterpreterScopeClosable c = interpreter.enterScope()) { | ||
interpreter.setLineNumber(definitionLineNumber); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to reorient the interpreter when evaluating macro functions so we can correctly set the error line numbers from the original imported file. To do this, each MacroFunction
will keep track of the line number and position it was defined at in the original file. When it comes time for evaluation, the child interpreter will be oriented at this location.
(This also meant adding setters for lineNumber
and position
, which were previously readonly.)
* First draft of deferring from tag including macros * Checkstyle * Add more tests * Remove incorrect assert * Add test that checks deferring macros in depth and update DeferredValue & MacroFunction * Checkstyle * Make constructor private and overload instance method * Fixes #159: Adds dict support for DefaultFilter * removes undesired code from Filter.java * removes whitespaces from DateTimeFormatFilter.java * Fixes Style Check Errors * Removes stringArgs from DateTimeFormatFilter * Revert "Fixes #159: Adds dict support for DefaultFilter" * Changes DefaultFilter to extend AdvancedFilter * adds PyList support to ForTag * adds tests for ForTag * removes escape filter from fortag test * Fix resoncstruct end to honor trim tags * Add reconstructImage to MacroFunction * Add test for reconstructing macro with no trim tags * Whitespace fix * Implement safe filter as SafeString and handle SafeString in filters, functions and expressions (#385) * Start implementing safe filter * Remove comment about pass-through implementation * Return var if it's not instance of string instead of throwing * Add test for pass-through * Add support for SafeString to all filters which handle Strings * Remove utils for string reverse filter * Handle SafeString in truncate function * Formatting fix * Add SafeStringFilter interface * Handle safe strings in filters * rm trailing space * Formatting fixes * Move safeFilter method to Filter IF and remove SafeFilter IF * rm space * Change behaviour of Urlize filter to not always return a SafeString * Code style changes * Remove unnecessary call to safeString * Style fix * Add tests to handle Urlize string being escaped and made safe * rm hardcoded string * rm uneeded getValue * Add SafeString type as str * Handle SafeString in expressions Co-authored-by: Joe <Joeoh@users.noreply.github.com> * Fix template error line numbers (#380) * Fix line numbers * add to some more places * two levels deep test * Fix case with child interpreter * Add deprecation * Add another test * Update error messages * Fix up error messages and tests * Fix case with scopes * Add check for inherit * Put everything on the path stack * always push parent * remove callstack crud * Set back path management * Fix extend lineNo/position and keep track for each block * cleanup * Add test for extends * Add more tests * Check parent call stack for emtpy and line numbers * Fix test * Reorient line numbers when evaluating macros, make sure to pop import path off of stack * Add test for imported macros * Reorient line numbers when resolving blocks * Reorient line numbers when processing extend parents * Add tests for extends + includes * Revert "Implement safe filter as SafeString and handle SafeString in filters, functions and expressions (#385)" This reverts commit a6bea47. * Implement safe filter as SafeString and handle SafeString in filters, functions and expressions (#394) * Start implementing safe filter * Remove comment about pass-through implementation * Return var if it's not instance of string instead of throwing * Add test for pass-through * Handle safestrings and call implementor * Add tests * Handle SafeString in filter using kwargs * Handle safe strings in most simple expressions * Handle SafeString in IsUpperExp * Handle SafeString in filters. Allow overriding from within filter * Formatting fixes Co-authored-by: jkollmann <48923512+jkollmann@users.noreply.github.com> * First draft of deferring from tag including macros * Checkstyle * Add more tests * Remove incorrect assert * Add test that checks deferring macros in depth and update DeferredValue & MacroFunction * Checkstyle * Make constructor private and overload instance method * Fix resoncstruct end to honor trim tags * Add reconstructImage to MacroFunction * Add test for reconstructing macro with no trim tags * Whitespace fix * rm duplicate statement after merge Co-authored-by: Manish Devgan <manish.nsit8@gmail.com> Co-authored-by: Jeff Boulter <jeff@boulter.com> Co-authored-by: Joe <Joeoh@users.noreply.github.com> Co-authored-by: Matt Coley <matthewjcoley@gmail.com>
Use the line number of when a path was pushed to the pathStack as the line number for the error message rather than the line number of the error within another file.
TODO: much more testing if this approach is approved