-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
wrong line number in yaml syntax error message #104607
Comments
/sig usability /sig cli |
this is technically an issue that can be logged in the kubernetes-sigs/yaml repository. i recall discussions about doing some post processing on the errors to provide a better explanation to the user, but that seemed brittle. /sig api-machinery |
@neolit123 do you happen to remember who was involved in the discussions? I feel this issue will become a bit stale if we don't assign it to someone in concrete. |
there was an issue about this either in k-sigs/yaml or in k/k but i cannot find it. the SIG can ask for |
/assign Taking a look a it! :) |
Thank you @RinkiyaKeDad ! |
Thank you @neolit123 for the answer! |
Questions from slack thread: The changes will be made to yaml.go, right? Also can someone please point me to how I can test the changes I make to that file? |
yaml.go seems the right place. to test the change you should feed erroneous input and see if the error output can be modified. but not sure if API machinery would like to have this changed. |
actually, reading the OP again,
this seems like a problem with the code in apimachinery to split documents: the code works, but you have a source YAML with N yaml documents separated by so somehow, the error must include document number N to point the user at the right place. |
Well, even with the document number, the user would have to manually count the documents and then the lines inside the documents. Ideally kubectl would return the actual line number in the file. All text editors count line numbers in files starting from the top of the file. |
true, returning the doc number is one option. calculating the line number in the original multi-doc is doable but likely trickier. |
Yeah, I think it's better to a) do a sweeping overlook about the errors we return, such that we always return struct errors usable with If we redesign sigs.k8s.io/yaml (which I think we should, anyways, ref: kubernetes-sigs/yaml#61 and kubernetes-sigs/yaml#59), we should have this at the forefront of what we do, but I think these changes are large and influential enough to require significant documentation and specification. |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
I recently faced this issue myself. When debugged a bit, I found that the error with the line number is not in sigs/yaml but a level deeper, in gopkg/yaml. and the splitting of the YAML file happens in the apimachinery itself. So, IMO, the sigs or gopkg's YAML package needn't know about the multi-resource YAML file at all. The apimachinery/cli-runtime should add the error's actual line number. These packages can derive the number of lines in each resource definition, but extracting the erroneous line's number from the wrapped error is not that straightforward. One approach that I can think of is using the regex match on the error message (if that is conventionally acceptable here). Once extracted, the error should be wrapped with aggregated line number (no. of lines in previous resources in the YAML file + separators + erroneous line's number). The final error should look something like this:
where |
What happened:
I tried to apply a Kubefile that contained a yaml syntax error.
The following error was returned
The error was not on line 13 of the actual file. The file was a multi resource file, and the error was on line 13 of the 3rd resource.
What you expected to happen:
I expect kubectl to return an actionable error message that points to the place where the syntax error is. Ideally, it would give the actual line where the error is in the file, the resource, and would print the incriminated lines.
How to reproduce it (as minimally and precisely as possible):
Apply a multi resource yaml file with a syntax error that is not on the first resource.
Environment:
kubectl version
):Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.5", GitCommit:"6b1d87acf3c8253c123756b9e61dac642678305f", GitTreeState:"archive", BuildDate:"2021-03-30T00:00:00Z", GoVersion:"go1.16", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.2-eks-0389ca3", GitCommit:"8a4e27b9d88142bbdd21b997b532eb6d493df6d2", GitTreeState:"clean", BuildDate:"2021-07-31T01:34:46Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"linux/amd64"}
cat /etc/os-release
): Fedora 34The text was updated successfully, but these errors were encountered: