-
Notifications
You must be signed in to change notification settings - Fork 47
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
refactor: move error handling code to internal/errors, move SetMap to internal/schema #467
Conversation
internal/utils/utils.go
Outdated
@@ -0,0 +1,36 @@ | |||
package utils |
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.
Since this is a helper for working with schemas, I think we could have package schema
and this file could be set_map.go
internal/utils/utils.go
Outdated
// errors. Typically d.Set is not error checked. This helper makes checking | ||
// those errors less tedious. Because this works with a map, the order of the | ||
// errors would not be predictable, to avoid this the errors will be sorted. | ||
func SetMap(d *schema.ResourceData, m map[string]interface{}) 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.
Not in scope for this PR, but looking at how and where this helper is used, I'm not convinced it's really necessary.
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.
The pattern SetMap was made to simplify was
d.Set("foo", foo)
d.Set("bar", bar)
this pattern is both repetitive and common, but is also bad practice.
d.Set
can return an error and those errors were seldom checked. When they are checked, you end up with resources with 10-30 lines for attribute setting and an extra 20-60 lines of checking (if err != nil {\n return nil, err\n}\n
).
1e5b977
to
6d0b7a5
Compare
@displague @ctreatma I renamed the packages to |
@@ -0,0 +1,36 @@ | |||
package utils |
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.
nit: we can correct this later as minor cleanup.
the package name should match -- schema
underscores in filenames can be interpreted as compiler hints, as in _arm64.go
. I try to avoid them.
In this case, maps.go could be an alternative.
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.
approving assuming e2e results look reasonable
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #467 +/- ##
==========================================
- Coverage 60.11% 59.78% -0.34%
==========================================
Files 99 97 -2
Lines 20045 19807 -238
==========================================
- Hits 12051 11841 -210
+ Misses 7691 7672 -19
+ Partials 303 294 -9 ☔ View full report in Codecov by Sentry. |
Part of #106
This PR is moving error code to internal/errors, and SetMap function to internal/schema.
I'm open to change the directory/package names.