Skip to content

Commit

Permalink
improving error message when unable to parse UUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
tmunzer committed Aug 22, 2024
1 parent f22a283 commit daab1d9
Show file tree
Hide file tree
Showing 51 changed files with 1,140 additions and 403 deletions.
36 changes: 18 additions & 18 deletions internal/provider/device_ap.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ func (r *deviceApResource) Create(ctx context.Context, req resource.CreateReques
siteId, err := uuid.Parse(plan.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_ap site_id from plan",
"Could not get device_ap site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_ap\" resource",
"Could parse the UUID: "+err.Error(),
)
return
}

deviceId, err := uuid.Parse(plan.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_ap device_id from plan",
"Could not get device_ap device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_ap\" resource",
"Could parse the UUID: "+err.Error(),
)
return
}
Expand Down Expand Up @@ -138,17 +138,17 @@ func (r *deviceApResource) Read(ctx context.Context, req resource.ReadRequest, r
siteId, err := uuid.Parse(state.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_ap site_id from state",
"Could not get device_ap site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_ap\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}

deviceId, err := uuid.Parse(state.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_ap device_id from state",
"Could not get device_ap device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_ap\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand Down Expand Up @@ -207,17 +207,17 @@ func (r *deviceApResource) Update(ctx context.Context, req resource.UpdateReques
siteId, err := uuid.Parse(plan.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_ap site_id from state",
"Could not get device_ap site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_ap\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}

deviceId, err := uuid.Parse(plan.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_ap device_id from state",
"Could not get device_ap device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_ap\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand Down Expand Up @@ -269,17 +269,17 @@ func (r *deviceApResource) Delete(ctx context.Context, req resource.DeleteReques
siteId, err := uuid.Parse(state.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_ap site_id from state",
"Could not get device_ap site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_ap\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}

deviceId, err := uuid.Parse(state.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_ap device_id from state",
"Could not get device_ap device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_ap\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand All @@ -299,8 +299,8 @@ func (r *deviceApResource) ImportState(ctx context.Context, req resource.ImportS
_, err := uuid.Parse(req.ID)
if err != nil {
resp.Diagnostics.AddError(
"Error getting org id from import",
"Could not get org id, unexpected error: "+err.Error(),
"Invalid \"id\" value for \"device_ap\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/device_ap_stats_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (d *deviceApStatsDataSource) Read(ctx context.Context, req datasource.ReadR
orgId, err := uuid.Parse(ds.OrgId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting org_id from ds",
"Could not get org_id, unexpected error: "+err.Error(),
"Invalid \"org_id\" value for \"device_ap_stats\" data_source",
"Could parse the UUID: "+err.Error(),
)
return
}
Expand Down
36 changes: 18 additions & 18 deletions internal/provider/device_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ func (r *deviceGatewayResource) Create(ctx context.Context, req resource.CreateR
siteId, err := uuid.Parse(plan.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway site_id from plan",
"Could not get device_gateway site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_gateway\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}

deviceId, err := uuid.Parse(plan.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway device_id from plan",
"Could not get device_gateway device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_gateway\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand Down Expand Up @@ -137,17 +137,17 @@ func (r *deviceGatewayResource) Read(ctx context.Context, req resource.ReadReque
siteId, err := uuid.Parse(state.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway site_id from state",
"Could not get device_gateway site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_gateway\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}

deviceId, err := uuid.Parse(state.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway device_id from state",
"Could not get device_gateway device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_gateway\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand Down Expand Up @@ -208,17 +208,17 @@ func (r *deviceGatewayResource) Update(ctx context.Context, req resource.UpdateR
siteId, err := uuid.Parse(plan.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway site_id from state",
"Could not get device_gateway site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_gateway\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}

deviceId, err := uuid.Parse(plan.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway device_id from state",
"Could not get device_gateway device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_gateway\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand Down Expand Up @@ -270,17 +270,17 @@ func (r *deviceGatewayResource) Delete(ctx context.Context, req resource.DeleteR
siteId, err := uuid.Parse(state.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway site_id from state",
"Could not get device_gateway site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_gateway\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}

deviceId, err := uuid.Parse(state.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway device_id from state",
"Could not get device_gateway device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_gateway\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand All @@ -300,8 +300,8 @@ func (r *deviceGatewayResource) ImportState(ctx context.Context, req resource.Im
_, err := uuid.Parse(req.ID)
if err != nil {
resp.Diagnostics.AddError(
"Error getting org id from import",
"Could not get org id, unexpected error: "+err.Error(),
"Invalid \"id\" value for \"org\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand Down
44 changes: 22 additions & 22 deletions internal/provider/device_gateway_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ func (r *deviceGatewayClusterResource) Create(ctx context.Context, req resource.
siteId, err := uuid.Parse(plan.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway_cluster site_id from plan",
"Could not get device_gateway_cluster site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_gateway_cluster\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}

deviceId, err := uuid.Parse(plan.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway_cluster device_id from plan",
"Could not get device_gateway_cluster device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_gateway_cluster\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand Down Expand Up @@ -130,17 +130,17 @@ func (r *deviceGatewayClusterResource) Read(ctx context.Context, req resource.Re
siteId, err := uuid.Parse(state.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway_cluster site_id from state",
"Could not get device_gateway_cluster site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_gateway_cluster\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}

deviceId, err := uuid.Parse(state.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway_cluster device_id from state",
"Could not get device_gateway_cluster device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_gateway_cluster\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand Down Expand Up @@ -197,17 +197,17 @@ func (r *deviceGatewayClusterResource) Update(ctx context.Context, req resource.
siteIdState, err := uuid.Parse(state.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway_cluster site_id from state",
"Could not get device_gateway_cluster site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_gateway_cluster\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}

deviceIdState, err := uuid.Parse(state.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway_cluster device_id from state",
"Could not get device_gateway_cluster device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_gateway_cluster\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand All @@ -227,17 +227,17 @@ func (r *deviceGatewayClusterResource) Update(ctx context.Context, req resource.
siteIdPlan, err := uuid.Parse(plan.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway_cluster site_id from state",
"Could not get device_gateway_cluster site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_gateway_cluster\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}

deviceIdPlan, err := uuid.Parse(plan.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway_cluster device_id from state",
"Could not get device_gateway_cluster device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_gateway_cluster\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand Down Expand Up @@ -278,17 +278,17 @@ func (r *deviceGatewayClusterResource) Delete(ctx context.Context, req resource.
siteId, err := uuid.Parse(state.SiteId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway_cluster site_id from state",
"Could not get device_gateway_cluster site_id, unexpected error: "+err.Error(),
"Invalid \"site_id\" value for \"device_gateway_cluster\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}

deviceId, err := uuid.Parse(state.DeviceId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting device_gateway_cluster device_id from state",
"Could not get device_gateway_cluster device_id, unexpected error: "+err.Error(),
"Invalid \"device_id\" value for \"device_gateway_cluster\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand All @@ -308,8 +308,8 @@ func (r *deviceGatewayClusterResource) ImportState(ctx context.Context, req reso
_, err := uuid.Parse(req.ID)
if err != nil {
resp.Diagnostics.AddError(
"Error getting org id from import",
"Could not get org id, unexpected error: "+err.Error(),
"Invalid \"id\" value for \"device_gateway_cluster\" resource",
"Could not parse the UUID: "+err.Error(),
)
return
}
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/device_gateway_stats_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (d *deviceGatewayStatsDataSource) Read(ctx context.Context, req datasource.
orgId, err := uuid.Parse(ds.OrgId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
"Error getting org_id from ds",
"Could not get org_id, unexpected error: "+err.Error(),
"Invalid \"org_id\" value for \"device_gateway_stats\" data_source",
"Could parse the UUID: "+err.Error(),
)
return
}
Expand Down
Loading

0 comments on commit daab1d9

Please sign in to comment.