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

Go113errors #160

Merged
merged 15 commits into from
Dec 3, 2021
Merged

Go113errors #160

merged 15 commits into from
Dec 3, 2021

Conversation

willbeason
Copy link
Member

@willbeason willbeason commented Nov 16, 2021

Move pkg/client to use go113 errors conventions.

In general, move to using constant base errors and wrap them with fmt.Errorf. Also make tests check that the expected error is returned.

In many cases I've extended tests to make them more flexible to accommodate this. I've made the tests more flexible, but haven't added examples of using that flexibility (for example, a client working with multiple targets). I intend to do so in a separate PR.

Fix a few concurrency bugs - the RW mutex wasn't properly guarding writes vs. reads for constraints. Also consider two Constraints with empty Specs to be "Semantically equal" as it is valid for Constraints to have empty specs.

@codecov-commenter
Copy link

codecov-commenter commented Nov 16, 2021

Codecov Report

Merging #160 (54e8b74) into master (217139c) will increase coverage by 0.40%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #160      +/-   ##
==========================================
+ Coverage   43.95%   44.35%   +0.40%     
==========================================
  Files          56       61       +5     
  Lines        3133     3206      +73     
==========================================
+ Hits         1377     1422      +45     
- Misses       1381     1413      +32     
+ Partials      375      371       -4     
Flag Coverage Δ
unittests 44.35% <ø> (+0.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...y-agent/frameworks/constraint/pkg/client/errors.go 0.00% <0.00%> (-44.45%) ⬇️
...t/frameworks/constraint/pkg/client/rego_helpers.go 80.00% <0.00%> (-2.61%) ⬇️
...gent/frameworks/constraint/pkg/schema/transform.go 75.00% <0.00%> (-1.93%) ⬇️
...nt/frameworks/constraint/pkg/client/crd_helpers.go 89.42% <0.00%> (-0.48%) ⬇️
...gent/frameworks/constraint/pkg/types/validation.go 13.33% <0.00%> (ø)
...gent/frameworks/constraint/pkg/client/error_map.go 0.00% <0.00%> (ø)
...nt/frameworks/constraint/pkg/client/client_opts.go 100.00% <0.00%> (ø)
...rks/constraint/pkg/core/constraints/constraints.go 100.00% <0.00%> (ø)
...ent/frameworks/constraint/pkg/client/query_opts.go 100.00% <0.00%> (ø)
...y-agent/frameworks/constraint/pkg/client/client.go 68.82% <0.00%> (+1.30%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 217139c...54e8b74. Read the comment docs.

Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

Thanks for doing all this!

LGTM pending addressing the nil-check issue for SemanticEqual.

There is one other nit about when to generate the list of known targets.

Lastly, you may want to change the state of this PR away from "draft" if it's ready for review.

constraint/pkg/client/client.go Outdated Show resolved Hide resolved
constraint/pkg/client/error_map.go Show resolved Hide resolved
@willbeason willbeason marked this pull request as ready for review November 23, 2021 18:45
@willbeason willbeason self-assigned this Nov 23, 2021

// Errors is a list of error.
//
// Deprecated: Use a structured result type if it is important to disambiguate
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean have individual custom types for each error?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's very situational. If we want to report individual error codes, then we should use a structured error type. If we need to programmatically work with information the error can communicate, then the error should have that structure. In general we want to treat errors as black-box as possible unless we have a functional reason to do otherwise.

Will Beason added 15 commits November 30, 2021 11:00
Remove ErrorList as it complicates code and results in repetitive errors
as implemented.

Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Also use cmp.Diff instead of reflect.DeepEqual

Signed-off-by: Will Beason <willbeason@google.com>
Make tests easily adaptable to multiple targets

Signed-off-by: Will Beason <willbeason@google.com>
Cover paths for go113 errors to ensure correct errors are returned.

Signed-off-by: Will Beason <willbeason@google.com>
It would return that Constraints were unequal if they both had no specs.
This is not intended behavior. Also add unit tests.

Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Use RLock for reading and Lock for writing. As-is could result in
concurrent reads and writes.

Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
@willbeason willbeason added this to the Rego Environment Sharding milestone Dec 1, 2021
@willbeason willbeason merged commit 352a1b3 into open-policy-agent:master Dec 3, 2021
@willbeason willbeason deleted the go113errors branch December 3, 2021 17:52
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.

None yet

4 participants