fix: improve error message when adoption-fields annotation is missing#231
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: shinichitazawa The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @shinichitazawa. Thanks for your PR. I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
When using `adoption-policy: adopt` without the `adoption-fields` annotation, `ExtractAdoptionFields` calls `json.Unmarshal` on an empty string, producing a generic "unexpected end of JSON input" error that gives no indication of the actual problem. This change adds an explicit empty-string check that returns a descriptive error explaining that the `adoption-fields` annotation is required, and wraps JSON parse errors with context about which annotation failed. Fixes aws-controllers-k8s/community#2824
bd55eae to
64a8f3b
Compare
Description
When using
services.k8s.aws/adoption-policy: adoptwithout theservices.k8s.aws/adoption-fieldsannotation,ExtractAdoptionFieldsinpkg/runtime/util.gocallsjson.Unmarshalon an empty string, producing the generic Go errorunexpected end of JSON input.This error gives no indication that the
adoption-fieldsannotation is missing, making it very difficult to diagnose — especially since it becomes aTerminalErrorthat permanently blocks reconciliation.Changes
ExtractAdoptionFieldsthat returns a descriptive error message explaining that theadoption-fieldsannotation is required whenadoption-policyis set toadoptjson.Unmarshalerror withfmt.Errorfand%wto provide context about which annotation failed to parseBefore
After
Testing
go test ./pkg/runtime/...)Fixes aws-controllers-k8s/community#2824
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.