Skip to content
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

Better/less verbose error formatting? #261

Closed
carlpett opened this issue Feb 13, 2024 · 2 comments
Closed

Better/less verbose error formatting? #261

carlpett opened this issue Feb 13, 2024 · 2 comments

Comments

@carlpett
Copy link
Contributor

carlpett commented Feb 13, 2024

Hey,
Since v0.6/#168 the errors on failed validations have gotten a lot more verbose/noisier. I suspect a lot of this comes from the new underlying library, but is there something we can do to support reformatting them?

Example of the same error in v0.5 vs v0.6:
ScaledObject so is invalid: For field spec.triggers.0: Additional property metricType is not allowed
vs
ScaledObject so is invalid: problem validating schema. Check JSON formatting: jsonschema: '/spec/triggers/0' does not validate with file:///var/cache/kubeconform/crds/scaledobject_v1alpha1.json#/properties/spec/properties/triggers/items/additionalProperties: additionalProperties 'metricType' not allowed

We've rolled back after complaints from internal users about it being much harder to figure out what is wrong. For such end users, the schema file location is not very helpful at all, but takes a lot of visual space. Similarly, there's a lot of error wrapping that's relevant when hacking on kubeconform itself.

@yannh
Copy link
Owner

yannh commented Mar 3, 2024

Hi @carlpett , this is by design - actually made to make it easier to understand exactly what is wrong. In some cases when using registries, seeing what schema the resource is validated against is useful. Apart from the additional schema information, it seems pretty close to what it was before..

There is a JSON output, I guess if you pipe it to jq you could get a custom error message.

$ ./bin/kubeconform -output json fixtures/invalid.yaml { "resources": [ { "filename": "fixtures/invalid.yaml", "kind": "ReplicationController", "name": "bob", "version": "v1", "status": "statusInvalid", "msg": "problem validating schema. Check JSON formatting: jsonschema: '/spec/replicas' does not validate with https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master-standalone/replicationcontroller-v1.json#/properties/spec/properties/replicas/type: expected integer or null, but got string", "validationErrors": [ { "path": "/spec/replicas", "msg": "expected integer or null, but got string" } ] } ] }

./bin/kubeconform -output json fixtures/invalid.yaml | jq -r '.resources[] | "Error found in "+ .kind + " "+ .name +" in "+ .filename' Error found in ReplicationController bob in fixtures/invalid.yaml

But I don't think I would really remove information from the output as it is now 🙇

@yannh yannh closed this as completed Mar 3, 2024
@carlpett
Copy link
Contributor Author

carlpett commented Mar 3, 2024

Hi @yannh,
Fair enough, perhaps our users or usage (schemas are prepackaged) are atypical. Thanks for the json idea though, I think we can do something with that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants