Skip to content

Commit f3f3741

Browse files
authored
Merge pull request #131 from OpenVPN/improve-read-error-messages
Add entity ID to error messages for read operations
2 parents b00680b + 01ef20c commit f3f3741

29 files changed

+70
-75
lines changed

cloudconnexa/data_source_access_group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func dataSourceAccessGroupRead(ctx context.Context, data *schema.ResourceData, i
6060
group, err := c.AccessGroups.Get(id)
6161

6262
if err != nil {
63-
return diag.FromErr(err)
63+
return append(diags, diag.Errorf("Failed to get access group with ID: %s, %s", id, err)...)
6464
}
6565
if group == nil {
6666
return append(diags, diag.Errorf("Access Group with id %s was not found", id)...)

cloudconnexa/data_source_host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func dataSourceHostRead(ctx context.Context, d *schema.ResourceData, m interface
7070
id := d.Get("id").(string)
7171
host, err := c.Hosts.Get(id)
7272
if err != nil {
73-
return append(diags, diag.FromErr(err)...)
73+
return append(diags, diag.Errorf("Failed to get host with ID: %s, %s", id, err)...)
7474
}
7575
if host == nil {
7676
return append(diags, diag.Errorf("Host with id %s was not found", id)...)

cloudconnexa/data_source_host_application.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package cloudconnexa
22

33
import (
44
"context"
5-
"strings"
6-
75
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
86
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
97
"github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"
@@ -66,11 +64,7 @@ func dataSourceHostApplicationRead(ctx context.Context, data *schema.ResourceDat
6664
id := data.Get("id").(string)
6765
application, err = c.HostApplications.Get(id)
6866
if err != nil {
69-
if strings.Contains(err.Error(), "status code: 404") {
70-
return append(diags, diag.Errorf("Application with id %s was not found", id)...)
71-
} else {
72-
return append(diags, diag.FromErr(err)...)
73-
}
67+
return append(diags, diag.Errorf("Failed to get host application with ID: %s, %s", id, err)...)
7468
}
7569
if application == nil {
7670
return append(diags, diag.Errorf("Application with id %s was not found", id)...)

cloudconnexa/data_source_host_connector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func dataSourceHostConnectorRead(ctx context.Context, d *schema.ResourceData, m
8686
id := d.Get("id").(string)
8787
connector, err = c.HostConnectors.GetByID(id)
8888
if err != nil {
89-
return append(diags, diag.FromErr(err)...)
89+
return append(diags, diag.Errorf("Failed to get host connector with ID: %s, %s", id, err)...)
9090
}
9191
if connector == nil {
9292
return append(diags, diag.Errorf("Connector with id %s was not found", id)...)

cloudconnexa/data_source_host_ip_service.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ func dataSourceHostIPService() *schema.Resource {
6262
// - diag.Diagnostics: Diagnostics containing any errors that occurred during the operation
6363
func dataSourceHostIPServiceRead(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
6464
c := i.(*cloudconnexa.Client)
65-
service, err := c.HostIPServices.Get(data.Get("id").(string))
65+
var diags diag.Diagnostics
66+
id := data.Get("id").(string)
67+
service, err := c.HostIPServices.Get(id)
6668

6769
if err != nil {
68-
return diag.FromErr(err)
70+
return append(diags, diag.Errorf("Failed to get host IP service with ID: %s, %s", id, err)...)
6971
}
7072
setHostIpServiceResourceData(data, service)
7173
return nil

cloudconnexa/data_source_location_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func dataSourceLocationContextRead(ctx context.Context, data *schema.ResourceDat
7070
context, err := c.LocationContexts.Get(id)
7171

7272
if err != nil {
73-
return diag.FromErr(err)
73+
return append(diags, diag.Errorf("Failed to get location context with ID: %s, %s", id, err)...)
7474
}
7575
if context == nil {
7676
return append(diags, diag.Errorf("Location Context with ID %s was not found", id)...)

cloudconnexa/data_source_network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func dataSourceNetworkRead(ctx context.Context, d *schema.ResourceData, m interf
7575
id := d.Get("id").(string)
7676
network, err = c.Networks.Get(id)
7777
if err != nil {
78-
return append(diags, diag.FromErr(err)...)
78+
return append(diags, diag.Errorf("Failed to get network with ID: %s, %s", id, err)...)
7979
}
8080
if network == nil {
8181
return append(diags, diag.Errorf("Network with id %s was not found", id)...)

cloudconnexa/data_source_network_application.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package cloudconnexa
22

33
import (
44
"context"
5-
"strings"
6-
75
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
86
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
97
"github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"
@@ -64,11 +62,7 @@ func dataSourceNetworkApplicationRead(ctx context.Context, data *schema.Resource
6462
id := data.Get("id").(string)
6563
application, err = c.NetworkApplications.Get(id)
6664
if err != nil {
67-
if strings.Contains(err.Error(), "status code: 404") {
68-
return append(diags, diag.Errorf("Application with id %s was not found", id)...)
69-
} else {
70-
return append(diags, diag.FromErr(err)...)
71-
}
65+
return append(diags, diag.Errorf("Failed to get network application with ID: %s, %s", id, err)...)
7266
}
7367
if application == nil {
7468
return append(diags, diag.Errorf("Application with id %s was not found", id)...)

cloudconnexa/data_source_network_connector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func dataSourceNetworkConnectorRead(ctx context.Context, d *schema.ResourceData,
8686
id := d.Get("id").(string)
8787
connector, err = c.NetworkConnectors.GetByID(id)
8888
if err != nil {
89-
return append(diags, diag.FromErr(err)...)
89+
return append(diags, diag.Errorf("Failed to get network connector with ID: %s, %s", id, err)...)
9090
}
9191
if connector == nil {
9292
return append(diags, diag.Errorf("Connector with id %s was not found", id)...)

cloudconnexa/data_source_network_ip_service.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ func dataSourceNetworkIPService() *schema.Resource {
6363
// - diag.Diagnostics: Diagnostics containing any errors that occurred during the operation
6464
func dataSourceNetworkIPServiceRead(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
6565
c := i.(*cloudconnexa.Client)
66-
service, err := c.NetworkIPServices.Get(data.Get("id").(string))
66+
var diags diag.Diagnostics
67+
id := data.Get("id").(string)
68+
service, err := c.NetworkIPServices.Get(id)
6769

6870
if err != nil {
69-
return diag.FromErr(err)
71+
return append(diags, diag.Errorf("Failed to get network IP service with ID: %s, %s", id, err)...)
7072
}
7173
setNetworkIpServiceResourceData(data, service)
7274
return nil

0 commit comments

Comments
 (0)