Closed nairb774 closed 4 years ago
very interesting, will take a look. thanks for submitting this.
We (i.e. @pivotal-dean and I) took a closer look at this symptom, today.
TL;DR. the original Starlark scanner detects an indentation error, even though it is not an error for ytt's augmenting scanner. We are considering two strategies: either remove the original scanner's error checking or insert whitespace to satisfy it.
Here's what we know:
BlockScanner
— which interprets a :\n
to open a block and the end
keyword closes a block.BlockScanner
continues to depend on the original scanner for tokenization.Instruction
s: which is the Starlark equivalent (i.e. a function call that inserts that value into the YAML AST) — e.g. __ytt_tpl23_start_node(3)
inserts a Document Start node.The error we're seeing here is a result of the original scanner detecting what it believes is an error in indentation:
__ytt_tpl23_start_node(3)
is fully outdented — so, the original scanner decides that we've closed all prior a levels of indentation;_ytt_tpl23_set_node(3)
) is also fully outdented, no indentation issue here;end
on line 7 is indented 4 spaces — so, the original scanner records that we have one legit indent at 4 spaces;end
on line 8 is indented 2 spaces (an outdent with respect to the prior line). However, the original scanner knows of no indent at 2 spaces. This is an indentation error since every outdent must correspond to a prior indent.The bug is that this behavior is not ytt's intent: it attempts to ignore Starlark's original scanner's tracking of whitespace indentation. ...
We have come up with a few of ideas to address this:
We're continuing to consider other options. This is what we've seen and considered so far.
(updated: reconsidering trimming source lines + disallowing multi-line strings in favor of string concatenation)
I spent a good 30 to 45 minutes trying to figure out the bug in the code before filing. After reading your description, I had no chance in that time frame :) Especially given how the repeated indentation worked (4 spaces, 4 spaces, 0 spaces), I was looking for an off-by-one error somewhere since all of the test samples always seemed to stop at 2 levels deep. Regardless, love the project.
Really appreciate your putting in that effort. The issue is well described. Having the distilled example made it easier for us to reproduce and hone-in on the essential parts.
Yeah, this took us a while to unpack the situation, ourselves (we didn't lean on @cppforlife's sherpa skills for this one).
fix will be included in v0.28.0
included in https://github.com/k14s/ytt/releases/tag/v0.28.0
All possible working solution [Solved] IndentationError: unindent does not match any outer indentation level
I stumbled across an odd interaction between ytt and starlark. The following is a minimal reproducing snippet:
Which results in the error (from adding a sample to pkg/yamltemplate/filetests):
The following works correctly, though I would expect it to be wrong. Notice the second end is indented to match the first (innermost). So long as they have the same indentation, things seem to kind of work:
Last thing that I noticed is that it seems to be related to the
---
within the loop.