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

Only attempt object scheme parsing if object is not registered in meta #300

Merged
merged 2 commits into from
Oct 29, 2021

Conversation

hasheddan
Copy link
Member

Description of your changes

Updates the package parsing logic to only attempt decoding with the
object scheme in the case that the error from decoding in the meta
scheme is due to the GVK not being registered. This does not change the
definition of a valid package, but does result in more informative
errors being returned when a package is invalid due to a malformed meta
type.

Signed-off-by: hasheddan georgedanielmangum@gmail.com

Fixes #299

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Tested with example in #299 and returned the following error (this is using Crossplane CLI, but same parsing is used in package manager, minus the annotated file position):

kubectl crossplane: error: failed to build package: failed to parse package: {path:/home/dan/code/github.com/crossplane/crossplane/pack/crossplane.yaml position:0}: v1alpha1.Provider.Spec: v1alpha1.ProviderSpec.Controller: readObjectStart: expect { or n, but found ", error found in #10 byte of ...|troller":"image cros|..., bigger context ...|cp"},"name":"provider-gcp"},"spec":{"controller":"image crossplane/provider-gcp-controller:VERSION"}|...

Updates the package parsing logic to only attempt decoding with the
object scheme in the case that the error from decoding in the meta
scheme is due to the GVK not being registered. This does not change the
definition of a valid package, but does result in more informative
errors being returned when a package is invalid due to a malformed meta
type.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
@hasheddan hasheddan requested a review from negz October 29, 2021 20:04
// annotateErr annotates an error if the reader is an AnnotatedReadCloser.
func annotateErr(err error, reader io.ReadCloser) error {
if anno, ok := reader.(AnnotatedReadCloser); ok {
return errors.Wrap(err, fmt.Sprintf("%+v", anno.Annotate()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use errors.Wrapf here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yes good call 👍🏻

Updates error annotation formatting to use errors.Wrapf.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
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

Successfully merging this pull request may close these issues.

Malformed crossplane.yaml leads to misleading errors
2 participants