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

chore: rename errors.FriendlyError to errors.Friendly #786

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion equinix/data_source_metal_spot_market_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func dataSourceMetalSpotMarketRequestRead(ctx context.Context, d *schema.Resourc

smr, _, err := client.SpotMarketRequests.Get(id, &packngo.GetOptions{Includes: []string{"project", "devices", "facilities", "metro"}})
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
if equinix_errors.IsNotFound(err) {
d.SetId("")
return nil
Expand Down
4 changes: 2 additions & 2 deletions equinix/resource_metal_bgp_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
DefaultRoute: &defaultRoute,
})
if err != nil {
return equinix_errors.FriendlyError(err)
return equinix_errors.Friendly(err)
}

d.SetId(bgpSession.ID)
Expand All @@ -80,7 +80,7 @@
bgpSession, _, err := client.BGPSessions.Get(d.Id(),
&packngo.GetOptions{Includes: []string{"device"}})
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
if equinix_errors.IsNotFound(err) {
log.Printf("[WARN] BGP Session (%s) not found, removing from state", d.Id())

Expand All @@ -95,10 +95,10 @@
defaultRoute = true
}
}
d.Set("device_id", bgpSession.Device.ID)

Check failure on line 98 in equinix/resource_metal_bgp_session.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `d.Set` is not checked (errcheck)
d.Set("address_family", bgpSession.AddressFamily)

Check failure on line 99 in equinix/resource_metal_bgp_session.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `d.Set` is not checked (errcheck)
d.Set("status", bgpSession.Status)

Check failure on line 100 in equinix/resource_metal_bgp_session.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `d.Set` is not checked (errcheck)
d.Set("default_route", defaultRoute)

Check failure on line 101 in equinix/resource_metal_bgp_session.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `d.Set` is not checked (errcheck)
d.SetId(bgpSession.ID)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion equinix/resource_metal_device_network_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func resourceMetalDeviceNetworkTypeRead(d *schema.ResourceData, meta interface{}

_, devNType, err := getDevIDandNetworkType(d, client)
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)

if equinix_errors.IsNotFound(err) {
log.Printf("[WARN] Device (%s) for Network Type request not found, removing from state", d.Id())
Expand Down
4 changes: 2 additions & 2 deletions equinix/resource_metal_ip_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
client := meta.(*config.Config).Metal
assignment, _, err := client.DeviceIPs.Get(d.Id(), nil)
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)

// If the IP attachment was already destroyed, mark as succesfully gone.
if equinix_errors.IsNotFound(err) {
Expand All @@ -71,12 +71,12 @@
}

d.SetId(assignment.ID)
d.Set("address", assignment.Address)

Check failure on line 74 in equinix/resource_metal_ip_attachment.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `d.Set` is not checked (errcheck)
d.Set("gateway", assignment.Gateway)

Check failure on line 75 in equinix/resource_metal_ip_attachment.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `d.Set` is not checked (errcheck)
d.Set("network", assignment.Network)

Check failure on line 76 in equinix/resource_metal_ip_attachment.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `d.Set` is not checked (errcheck)
d.Set("netmask", assignment.Netmask)

Check failure on line 77 in equinix/resource_metal_ip_attachment.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `d.Set` is not checked (errcheck)
d.Set("address_family", assignment.AddressFamily)

Check failure on line 78 in equinix/resource_metal_ip_attachment.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `d.Set` is not checked (errcheck)
d.Set("cidr", assignment.CIDR)

Check failure on line 79 in equinix/resource_metal_ip_attachment.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `d.Set` is not checked (errcheck)
d.Set("public", assignment.Public)
d.Set("management", assignment.Management)
d.Set("manageable", assignment.Manageable)
Expand All @@ -96,7 +96,7 @@

resp, err := client.DeviceIPs.Unassign(d.Id())
if equinix_errors.IgnoreResponseErrors(equinix_errors.HttpForbidden, equinix_errors.HttpNotFound)(resp, err) != nil {
return equinix_errors.FriendlyError(err)
return equinix_errors.Friendly(err)
}

d.SetId("")
Expand Down
6 changes: 3 additions & 3 deletions equinix/resource_metal_port_vlan_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func resourceMetalPortVlanAttachmentRead(d *schema.ResourceData, meta interface{

dev, _, err := client.Devices.Get(deviceID, &packngo.GetOptions{Includes: []string{"virtual_networks,project,native_virtual_network"}})
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)

if equinix_errors.IsNotFound(err) {
log.Printf("[WARN] Device (%s) for Port Vlan Attachment not found, removing from state", d.Id())
Expand Down Expand Up @@ -265,11 +265,11 @@ func resourceMetalPortVlanAttachmentDelete(d *schema.ResourceData, meta interfac
portName := d.Get("port_name").(string)
port, err := client.DevicePorts.GetPortByName(deviceID, portName)
if err != nil {
return equinix_errors.FriendlyError(err)
return equinix_errors.Friendly(err)
}
_, _, err = client.DevicePorts.Bond(port, false)
if err != nil {
return equinix_errors.FriendlyError(err)
return equinix_errors.Friendly(err)
}
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions equinix/resource_metal_project_api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func resourceMetalAPIKeyCreate(d *schema.ResourceData, meta interface{}) error {

apiKey, _, err := client.APIKeys.Create(createRequest)
if err != nil {
return equinix_errors.FriendlyError(err)
return equinix_errors.Friendly(err)
}

d.SetId(apiKey.ID)
Expand Down Expand Up @@ -106,7 +106,7 @@ func resourceMetalAPIKeyRead(d *schema.ResourceData, meta interface{}) error {
}

if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
// If the key is somehow already destroyed, mark as
// succesfully gone
if equinix_errors.IsNotFound(err) {
Expand Down Expand Up @@ -143,7 +143,7 @@ func resourceMetalAPIKeyDelete(d *schema.ResourceData, meta interface{}) error {

resp, err := client.APIKeys.Delete(d.Id())
if equinix_errors.IgnoreResponseErrors(equinix_errors.HttpForbidden, equinix_errors.HttpNotFound)(resp, err) != nil {
return equinix_errors.FriendlyError(err)
return equinix_errors.Friendly(err)
}

d.SetId("")
Expand Down
2 changes: 1 addition & 1 deletion equinix/resource_metal_reserved_ip_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func resourceMetalReservedIPBlockRead(ctx context.Context, d *schema.ResourceDat

reservedBlock, _, err := client.ProjectIPs.Get(id, getOpts)
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
if equinix_errors.IsNotFound(err) {
log.Printf("[WARN] Reserved IP Block (%s) not found, removing from state", d.Id())
d.SetId("")
Expand Down
2 changes: 1 addition & 1 deletion equinix/resource_metal_spot_market_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func resourceMetalSpotMarketRequestRead(ctx context.Context, d *schema.ResourceD

smr, _, err := client.SpotMarketRequests.Get(d.Id(), &packngo.GetOptions{Includes: []string{"project", "devices", "facilities", "metro"}})
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
if equinix_errors.IsNotFound(err) {
log.Printf("[WARN] SpotMarketRequest (%s) not found, removing from state", d.Id())
d.SetId("")
Expand Down
4 changes: 2 additions & 2 deletions internal/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/packethost/packngo"
)

// FriendlyError improves error messages when the API error is blank or in an
// Friendly improves error messages when the API error is blank or in an
// alternate format (as is the case with invalid token or loadbalancer errors)
func FriendlyError(err error) error {
func Friendly(err error) error {
if e, ok := err.(*packngo.ErrorResponse); ok {
resp := e.Response
errors := Errors(e.Errors)
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/metal/device/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func hwReservationStateRefreshFunc(ctx context.Context, client *metalv1.APIClien
state := deprovisioning
switch {
case err != nil:
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
state = errstate
case r != nil && r.GetProvisionable():
state = provisionable
Expand Down
10 changes: 5 additions & 5 deletions internal/resources/metal/device/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ func resourceMetalDeviceCreate(ctx context.Context, d *schema.ResourceData, meta
projectID := d.Get("project_id").(string)
newDevice, _, err := client.DevicesApi.CreateDevice(ctx, projectID).CreateDeviceRequest(createRequest).Execute()
if err != nil {
retErr := equinix_errors.FriendlyError(err)
retErr := equinix_errors.Friendly(err)
if equinix_errors.IsNotFound(retErr) {
retErr = fmt.Errorf("%s, make sure project \"%s\" exists", retErr, projectID)
}
Expand Down Expand Up @@ -737,7 +737,7 @@ func resourceMetalDeviceUpdate(ctx context.Context, d *schema.ResourceData, meta
start := time.Now()
if !reflect.DeepEqual(ur, metalv1.DeviceUpdateInput{}) {
if _, _, err := client.DevicesApi.UpdateDevice(ctx, d.Id()).DeviceUpdateInput(ur).Execute(); err != nil {
return diag.FromErr(equinix_errors.FriendlyError(err))
return diag.FromErr(equinix_errors.Friendly(err))
}
}

Expand Down Expand Up @@ -774,7 +774,7 @@ func doReinstall(ctx context.Context, client *metalv1.APIClient, d *schema.Resou
}

if _, err := client.DevicesApi.PerformAction(ctx, d.Id()).DeviceActionInput(reinstallOptions).Execute(); err != nil {
return equinix_errors.FriendlyError(err)
return equinix_errors.Friendly(err)
}

updateTimeout := d.Timeout(schema.TimeoutUpdate) - 30*time.Second - time.Since(start)
Expand All @@ -799,7 +799,7 @@ func resourceMetalDeviceDelete(ctx context.Context, d *schema.ResourceData, meta

resp, err := client.DevicesApi.DeleteDevice(ctx, d.Id()).ForceDelete(fdv).Execute()
if equinix_errors.IgnoreHttpResponseErrors(equinix_errors.HttpForbidden, equinix_errors.HttpNotFound)(resp, err) != nil {
return diag.FromErr(equinix_errors.FriendlyError(err))
return diag.FromErr(equinix_errors.Friendly(err))
}

resId, resIdOk := d.GetOk("deployed_hardware_reservation_id")
Expand Down Expand Up @@ -844,7 +844,7 @@ func WaitForActiveDevice(ctx context.Context, d *schema.ResourceData, meta inter
state, err := waitForDeviceAttribute(ctx, d, stateConf)
if err != nil {
d.SetId("")
fErr := equinix_errors.FriendlyError(err)
fErr := equinix_errors.Friendly(err)
if equinix_errors.IsForbidden(fErr) {
// If the device doesn't get to the active state, we can't recover it from here.

Expand Down
2 changes: 1 addition & 1 deletion internal/resources/metal/gateway/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func getGatewayAndParse(ctx context.Context, client *metalv1.APIClient, state *R
// API call to get the Metal Gateway
gw, _, err := client.MetalGatewaysApi.FindMetalGatewayById(ctx, id).Include(includes).Execute()
if err != nil {
return diags, equinix_errors.FriendlyError(err)
return diags, equinix_errors.Friendly(err)
}

// Parse the API response into the Terraform state
Expand Down
4 changes: 2 additions & 2 deletions internal/resources/metal/organization/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (r *DataSource) Read(
if !name.IsNull() {
orgList, _, err := client.Organizations.List(&packngo.GetOptions{Includes: []string{"address"}})
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
resp.Diagnostics.AddError(
"Error listing Organizations",
err.Error(),
Expand All @@ -77,7 +77,7 @@ func (r *DataSource) Read(
orgID := orgId.ValueString()
org, _, err := client.Organizations.Get(orgID, &packngo.GetOptions{Includes: []string{"address"}})
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
resp.Diagnostics.AddError(
"Error getting Organization",
err.Error(),
Expand Down
12 changes: 6 additions & 6 deletions internal/resources/metal/organization/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (r *Resource) Create(
if err != nil {
resp.Diagnostics.AddError(
"Failed to create Organizations",
equinix_errors.FriendlyError(err).Error(),
equinix_errors.Friendly(err).Error(),
)
return
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func (r *Resource) Read(
diags, err := getOrganizationAndParse(ctx, client, &state, id)
resp.Diagnostics.Append(diags...)
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)

// If the key is somehow already destroyed, mark as
// succesfully gone
Expand Down Expand Up @@ -210,7 +210,7 @@ func (r *Resource) Update(
// Update the resource
_, _, err := client.Organizations.Update(id, updateRequest)
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
resp.Diagnostics.AddError(
"Error updating resource",
"Could not update Metal Organization with ID "+id+": "+err.Error(),
Expand All @@ -222,7 +222,7 @@ func (r *Resource) Update(
diags, err := getOrganizationAndParse(ctx, client, &plan, id)
resp.Diagnostics.Append(diags...)
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
resp.Diagnostics.AddError(
"Error updating resource",
"Could not read Metal Organization with ID "+id+": "+err.Error(),
Expand Down Expand Up @@ -255,7 +255,7 @@ func (r *Resource) Delete(
// Use API client to delete the resource
deleteResp, err := client.Organizations.Delete(id)
if equinix_errors.IgnoreResponseErrors(equinix_errors.HttpForbidden, equinix_errors.HttpNotFound)(deleteResp, err) != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
resp.Diagnostics.AddError(
fmt.Sprintf("Failed to delete Organizations %s", id),
err.Error(),
Expand All @@ -268,7 +268,7 @@ func getOrganizationAndParse(ctx context.Context, client *packngo.Client, state
includes := &packngo.GetOptions{Includes: []string{"address"}}
org, _, err := client.Organizations.Get(id, includes)
if err != nil {
return diags, equinix_errors.FriendlyError(err)
return diags, equinix_errors.Friendly(err)
}
// Parse the API response into the Terraform state
diags = state.parse(ctx, org)
Expand Down
16 changes: 8 additions & 8 deletions internal/resources/metal/organization_member/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (r *Resource) Create(
listOpts := &packngo.ListOptions{Includes: []string{"user"}}
invitations, _, err := client.Invitations.List(orgID, listOpts)
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
// If the org was destroyed, mark as gone.
if equinix_errors.IsNotFound(err) {
plan.OrganizationID = basetypes.NewStringNull()
Expand All @@ -131,7 +131,7 @@ func (r *Resource) Create(

members, _, err := client.Members.List(orgID, listOpts)
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
// If the org was destroyed, mark as gone.
if equinix_errors.IsNotFound(err) {
return
Expand Down Expand Up @@ -189,7 +189,7 @@ func (r *Resource) Read(
listOpts := &packngo.ListOptions{Includes: []string{"user"}}
invitations, _, err := client.Invitations.List(orgID, listOpts)
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
// If the org was destroyed, mark as gone.
if equinix_errors.IsNotFound(err) {
data.OrganizationID = basetypes.NewStringNull()
Expand All @@ -204,7 +204,7 @@ func (r *Resource) Read(

members, _, err := client.Members.List(orgID, &packngo.GetOptions{Includes: []string{"user"}})
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
// If the org was destroyed, mark as gone.
if equinix_errors.IsNotFound(err) {
data.OrganizationID = basetypes.NewStringNull()
Expand Down Expand Up @@ -246,7 +246,7 @@ func (r *Resource) Delete(
listOpts := &packngo.ListOptions{Includes: []string{"user"}}
invitations, _, err := client.Invitations.List(data.OrganizationID.ValueString(), listOpts)
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
// If the org was destroyed, mark as gone.
if equinix_errors.IsNotFound(err) {
data.OrganizationID = types.StringNull()
Expand All @@ -261,7 +261,7 @@ func (r *Resource) Delete(

org, _, err := client.Organizations.Get(data.OrganizationID.ValueString(), &packngo.GetOptions{Includes: []string{"members", "members.user"}})
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
// If the org was destroyed, mark as gone.
if equinix_errors.IsNotFound(err) {
data.OrganizationID = types.StringNull()
Expand All @@ -284,7 +284,7 @@ func (r *Resource) Delete(
if member.isMember() {
_, err = client.Members.Delete(data.OrganizationID.ValueString(), member.Member.ID)
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
// If the member was deleted, mark as gone.
if equinix_errors.IsNotFound(err) {
data.OrganizationID = types.StringNull()
Expand All @@ -299,7 +299,7 @@ func (r *Resource) Delete(
} else if member.isInvitation() {
_, err = client.Invitations.Delete(member.Invitation.ID)
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
// If the invitation was deleted, mark as gone.
if equinix_errors.IsNotFound(err) {
data.OrganizationID = types.StringNull()
Expand Down
4 changes: 2 additions & 2 deletions internal/resources/metal/port/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func resourceMetalPortUpdate(ctx context.Context, d *schema.ResourceData, meta i
start := time.Now()
cpr, _, err := getClientPortResource(ctx, d, meta)
if err != nil {
return diag.FromErr(equinix_errors.FriendlyError(err))
return diag.FromErr(equinix_errors.Friendly(err))
}

for _, f := range [](func(context.Context, *ClientPortResource) error){
Expand All @@ -146,7 +146,7 @@ func resourceMetalPortUpdate(ctx context.Context, d *schema.ResourceData, meta i
updateNativeVlan,
} {
if err := f(ctx, cpr); err != nil {
return diag.FromErr(equinix_errors.FriendlyError(err))
return diag.FromErr(equinix_errors.Friendly(err))
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/resources/metal/project/bgp_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func fetchBGPConfig(ctx context.Context, client *metalv1.APIClient, projectID st

bgpConfig, _, err := client.BGPApi.FindBgpConfigByProject(ctx, projectID).Execute()
if err != nil {
friendlyErr := equinix_errors.FriendlyError(err)
friendlyErr := equinix_errors.Friendly(err)
diags.AddError(
"Error reading BGP configuration",
"Could not read BGP configuration for project with ID "+projectID+": "+friendlyErr.Error(),
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/metal/project_ssh_key/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (r *DataSource) Read(
// Use API client to list SSH keys
keysList, _, err := client.SSHKeysApi.FindProjectSSHKeys(ctx, projectID).Query(search).Execute()
if err != nil {
err = equinix_errors.FriendlyError(err)
err = equinix_errors.Friendly(err)
resp.Diagnostics.AddError(
"Error listing project ssh keys",
err.Error(),
Expand Down
Loading
Loading