-
Notifications
You must be signed in to change notification settings - Fork 301
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
Empty yaml documents should be ignored when importing lists #3464
Comments
This seems reasonable. Do you want to send a patch with a test? |
I would like to take a look at this issue |
The YAML decoder decodes an empty YAML as null, making it indistinguishable from an actual null. Would it be reasonable to ignore null when importing lists? |
@haoqixu yes, I think that's fine. The YAML spec strongly hints that an empty document is equivalent to a null value. |
What is the expected behavior when a document is not empty? Is it possible to handle missing keys gracefully for the general case? Say: ❯ cue import -l "strings.ToLower(metadata.namespace)" --list abc.yaml ---
metadata:
namespace: some-namespace
---
metadata:
name: some-name # missing namespace
---
metadata:
namespace: some-namespace |
If multiple behaviors are wanted depending on the use case, we could always rethink the flag slightly so that |
I wrote a testscript to think through this a bit more before we merge the change:
As of master, the cases with empty documents fais when using
With https://review.gerrithub.io/c/cue-lang/cue/+/1202049 at patchset 3 on top of master, the results with
The first case looks oddly inconsistent now, because we're not ignoring the empty document in that case. On one hand, keeping the nulls in means that we're more directly representing the list of documents from the original YAML. On the other hand, it's a bit odd that adding The second case looks like it's still a bug; we should not fail, for the sake of consistency. The third case looks OK; we are now ignoring the empty document as discussed. My thinking is as follows: |
This approach seems reasonable to me. |
After discussing with @rogpeppe and @mpvl we agreed on a simpler approach and smaller fix: make We came to the conclusion that always ignoring null values in @haoqixu are you happy to update https://review.gerrithub.io/c/cue-lang/cue/+/1202049 accordingly? Please also add more tests, in line with the testscript I shared above, to make sure we do what we would expect in each scenario. |
I also filed #3608 for an idea we had to extend the YAML encoding a bit too, so that it is able to omit empty or null documents entirely from an input. However, that's not needed to resolve the issue here with |
No problem. I have submitted another CL to add tests and will update CL 1202049 soon. |
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest stable release?
Yes.
What did you do?
Import a list of yaml documents and transform it with
-l
.abc.yaml
What did you expect to see?
It would be nice if this just didn't add anything to the list instead of failing. I use
cue import
a lot to import Helm charts and often, because Helm is just a bad text templating engine, it will include empty yaml documents. I therefore have to find the empty documents myself and run the import again.What did you see instead?
error evaluating label strings.ToLower(kind): reference "kind" not found
The text was updated successfully, but these errors were encountered: