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

refactor: move error handling code to internal/errors, move SetMap to internal/schema #467

Merged
merged 2 commits into from
Dec 4, 2023

Conversation

t0mk
Copy link
Contributor

@t0mk t0mk commented Nov 27, 2023

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.

@@ -0,0 +1,36 @@
package utils
Copy link
Contributor

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

// 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 {
Copy link
Contributor

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.

Copy link
Member

@displague displague Nov 28, 2023

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).

@t0mk t0mk force-pushed the error_to_/internal branch from 1e5b977 to 6d0b7a5 Compare December 4, 2023 12:57
@t0mk t0mk changed the title refactor: move error handling code to internal/errs, move SetMap to internal/utils refactor: move error handling code to internal/errors, move SetMap to internal/schema Dec 4, 2023
@t0mk
Copy link
Contributor Author

t0mk commented Dec 4, 2023

@displague @ctreatma I renamed the packages to errors and schema and imported them as equinix_errors and equinix_schema. Please take a look again.

@@ -0,0 +1,36 @@
package utils
Copy link
Member

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.

Copy link
Member

@displague displague left a 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-commenter
Copy link

codecov-commenter commented Dec 4, 2023

Codecov Report

Attention: 356 lines in your changes are missing coverage. Please review.

Comparison is base (26b2f3d) 60.11% compared to head (90d0053) 59.78%.
Report is 77 commits behind head on main.

Files Patch % Lines
equinix/fabric_mapping_helper.go 0.00% 54 Missing ⚠️
equinix/resource_fabric_cloud_router.go 0.00% 32 Missing ⚠️
equinix/resource_fabric_connection.go 0.00% 28 Missing ⚠️
equinix/resource_fabric_service_profile.go 0.00% 14 Missing ⚠️
equinix/resource_fabric_routing_protocol.go 0.00% 13 Missing ⚠️
equinix/resource_metal_device.go 76.36% 10 Missing and 3 partials ⚠️
equinix/resource_metal_organization_member.go 27.77% 13 Missing ⚠️
equinix/resource_metal_connection.go 50.00% 8 Missing and 1 partial ⚠️
equinix/resource_metal_vlan.go 43.75% 7 Missing and 2 partials ⚠️
equinix/resource_ecx_l2_connection.go 38.46% 8 Missing ⚠️
... and 39 more

❗ 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.
📢 Have feedback on the report? Share it here.

@t0mk t0mk merged commit cb37f06 into main Dec 4, 2023
4 of 5 checks passed
@t0mk t0mk deleted the error_to_/internal branch December 4, 2023 14:47
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.

4 participants