-
Notifications
You must be signed in to change notification settings - Fork 261
Unmarshall error details #1040
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
Unmarshall error details #1040
Conversation
53a9b48 to
1636b05
Compare
alpha/declcfg/load.go
Outdated
| if e, ok := err.(*json.UnmarshalFieldError); ok { | ||
| return e.Error() | ||
| } | ||
| if e, ok := err.(*json.InvalidUnmarshalError); ok { | ||
| return e.Error() | ||
| } | ||
| if e, ok := err.(*json.SyntaxError); ok { | ||
| return e.Error() | ||
| } | ||
| return err.Error() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the error type assertions that end up returning .Error() could be condensed down to return err.Error(), right?
(Also for future reference, it's typically preferential to use errors.As in cases like this, because it means you can still get to the error you're after even if some code in between you and the error site has wrapped it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was reviewer-bait. I was hoping that someone would be opinionated about some of these other error types. Otherwise, you're right ... they're just a series of "why didn't you just do the single fallthrough for all them" instead? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking a look at the additional different error types the only one I would probably do anything specific with is the json.SyntaxError type. I can see that this is another potential error that a user may want a more descriptive error for.
The json.InvalidUnmarshalError seems more related to an error from incorrect parameters passed to the json.Unmarshal function and the json.UnmarshalFieldError is now deprecated and no longer used so we don't need to do anything unique here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reviews, guys!
I updated the code to support both of the errors we're initially interested in, and also reformatted the output to make it more human-readable.
The error scenario reflected in the PR description now displays as:
./bin/opm render -o yaml /tmp/community-operator-index-4.12
2022/11/15 16:00:38 render reference "/tmp/community-operator-index-4.12": unmarshal error: json: cannot unmarshal number into Go struct field Property.properties.type of type string at offset 230 (indicated by <==)
{
"image": "quay.io/openshift-community-operators/zookeeper-operator@sha256:c55e04596b97a1571675d59a7594e6c28f819c5ba1b2907561219ef334f50002",
"name": "zookeeper-operator.v0.10.3",
"package": "zookeeper-operator",
"properties": [
{
"type": 4 <== ,
"value": {
"group": "zookeeper.streamnative.io",
"kind": "ZooKeeperCluster",
"version": "v1alpha1"
}
},
{
"type": "olm.package",
"value": {
"packageName": "zookeeper-operator",
"version": "0.10.3"
}
}
],
"relatedImages": [
{
"image": "docker.cloudsmith.io/streamnative/operators/zookeeper-operator:v0.10.3",
"name": ""
},
{
"image": "gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0",
"name": ""
},
{
"image": "quay.io/openshift-community-operators/zookeeper-operator@sha256:c55e04596b97a1571675d59a7594e6c28f819c5ba1b2907561219ef334f50002",
"name": ""
}
],
"schema": "olm.bundle"
}
Codecov Report
@@ Coverage Diff @@
## master #1040 +/- ##
==========================================
+ Coverage 51.95% 52.01% +0.05%
==========================================
Files 102 102
Lines 9215 9241 +26
==========================================
+ Hits 4788 4807 +19
- Misses 3514 3521 +7
Partials 913 913
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
everettraven
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: everettraven, grokspawn The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Jordan Keister <jordan@nimblewidget.com>
Signed-off-by: Jordan Keister <jordan@nimblewidget.com>
df934e9 to
6488837
Compare
|
/lgtm |
Description of the change:
Capture JSON unmarshal type violations in greater detail to help authors spot the issue.
for e.g., when we set a properties type entry as type 4 instead of a string, we get a more descriptive blob to help us spot the violation:
Solves #1039
Motivation for the change:
Reviewer Checklist
/docs