Skip to content

Commit 0e364b8

Browse files
refactor: use error.as instead of silencing linter
1 parent 6a484b1 commit 0e364b8

File tree

21 files changed

+92
-80
lines changed

21 files changed

+92
-80
lines changed

stackit/internal/services/iaas/networkarearegion/resource.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ func (r *networkAreaRegionResource) Read(ctx context.Context, req resource.ReadR
335335
networkAreaRegionResp, err := r.client.GetNetworkAreaRegion(ctx, organizationId, networkAreaId, region).Execute()
336336
if err != nil {
337337
var oapiErr *oapierror.GenericOpenAPIError
338-
ok := errors.As(err, &oapiErr)
339-
if ok && oapiErr.StatusCode == http.StatusNotFound {
338+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
340339
resp.State.RemoveResource(ctx)
341340
return
342341
}
@@ -452,8 +451,8 @@ func (r *networkAreaRegionResource) Delete(ctx context.Context, req resource.Del
452451
// Delete network area region configuration
453452
err = r.client.DeleteNetworkAreaRegion(ctx, organizationId, networkAreaId, region).Execute()
454453
if err != nil {
455-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
456-
if ok && oapiErr.StatusCode == http.StatusNotFound {
454+
var oapiErr *oapierror.GenericOpenAPIError
455+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
457456
return
458457
}
459458
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting network area region", fmt.Sprintf("Calling API: %v", err))

stackit/internal/services/iaas/networkarearoute/resource.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package networkarearoute
22

33
import (
4+
"errors"
45
"context"
56
"fmt"
67
"net/http"
@@ -419,8 +420,8 @@ func (r *networkAreaRouteResource) Read(ctx context.Context, req resource.ReadRe
419420

420421
networkAreaRouteResp, err := r.client.GetNetworkAreaRoute(ctx, organizationId, networkAreaId, region, networkAreaRouteId).Execute()
421422
if err != nil {
422-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
423-
if ok && oapiErr.StatusCode == http.StatusNotFound {
423+
var oapiErr *oapierror.GenericOpenAPIError
424+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
424425
resp.State.RemoveResource(ctx)
425426
return
426427
}
@@ -470,8 +471,8 @@ func (r *networkAreaRouteResource) Delete(ctx context.Context, req resource.Dele
470471
// Delete existing network
471472
err := r.client.DeleteNetworkAreaRoute(ctx, organizationId, networkAreaId, region, networkAreaRouteId).Execute()
472473
if err != nil {
473-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
474-
if ok && oapiErr.StatusCode == http.StatusNotFound {
474+
var oapiErr *oapierror.GenericOpenAPIError
475+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
475476
return
476477
}
477478
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting network area route", fmt.Sprintf("Calling API: %v", err))

stackit/internal/services/iaas/networkinterface/resource.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package networkinterface
22

33
import (
4+
"errors"
45
"context"
56
"fmt"
67
"net/http"
@@ -351,8 +352,8 @@ func (r *networkInterfaceResource) Read(ctx context.Context, req resource.ReadRe
351352

352353
networkInterfaceResp, err := r.client.GetNic(ctx, projectId, region, networkId, networkInterfaceId).Execute()
353354
if err != nil {
354-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
355-
if ok && oapiErr.StatusCode == http.StatusNotFound {
355+
var oapiErr *oapierror.GenericOpenAPIError
356+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
356357
resp.State.RemoveResource(ctx)
357358
return
358359
}
@@ -459,8 +460,8 @@ func (r *networkInterfaceResource) Delete(ctx context.Context, req resource.Dele
459460
// Delete existing network interface
460461
err := r.client.DeleteNic(ctx, projectId, region, networkId, networkInterfaceId).Execute()
461462
if err != nil {
462-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
463-
if ok && oapiErr.StatusCode == http.StatusNotFound {
463+
var oapiErr *oapierror.GenericOpenAPIError
464+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
464465
return
465466
}
466467
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting network interface", fmt.Sprintf("Calling API: %v", err))

stackit/internal/services/iaas/networkinterfaceattach/resource.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package networkinterfaceattach
22

33
import (
4+
"errors"
45
"context"
56
"fmt"
67
"net/http"
@@ -225,8 +226,8 @@ func (r *networkInterfaceAttachResource) Read(ctx context.Context, req resource.
225226

226227
nics, err := r.client.ListServerNICs(ctx, projectId, region, serverId).Execute()
227228
if err != nil {
228-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
229-
if ok && oapiErr.StatusCode == http.StatusNotFound {
229+
var oapiErr *oapierror.GenericOpenAPIError
230+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
230231
resp.State.RemoveResource(ctx)
231232
return
232233
}
@@ -295,8 +296,8 @@ func (r *networkInterfaceAttachResource) Delete(ctx context.Context, req resourc
295296
// Remove network_interface from server
296297
err := r.client.RemoveNicFromServer(ctx, projectId, region, serverId, network_interfaceId).Execute()
297298
if err != nil {
298-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
299-
if ok && oapiErr.StatusCode == http.StatusNotFound {
299+
var oapiErr *oapierror.GenericOpenAPIError
300+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
300301
return
301302
}
302303
core.LogAndAddError(ctx, &resp.Diagnostics, "Error removing network interface from server", fmt.Sprintf("Calling API: %v", err))

stackit/internal/services/iaas/volumeattach/resource.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package volumeattach
22

33
import (
4+
"errors"
45
"context"
56
"fmt"
67
"net/http"
@@ -247,8 +248,8 @@ func (r *volumeAttachResource) Read(ctx context.Context, req resource.ReadReques
247248

248249
_, err := r.client.GetAttachedVolume(ctx, projectId, region, serverId, volumeId).Execute()
249250
if err != nil {
250-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
251-
if ok && oapiErr.StatusCode == http.StatusNotFound {
251+
var oapiErr *oapierror.GenericOpenAPIError
252+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
252253
resp.State.RemoveResource(ctx)
253254
return
254255
}
@@ -300,8 +301,8 @@ func (r *volumeAttachResource) Delete(ctx context.Context, req resource.DeleteRe
300301
// Remove volume from server
301302
err := r.client.RemoveVolumeFromServer(ctx, projectId, region, serverId, volumeId).Execute()
302303
if err != nil {
303-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
304-
if ok && oapiErr.StatusCode == http.StatusNotFound {
304+
var oapiErr *oapierror.GenericOpenAPIError
305+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
305306
return
306307
}
307308
core.LogAndAddError(ctx, &resp.Diagnostics, "Error removing volume from server", fmt.Sprintf("Calling API: %v", err))

stackit/internal/services/kms/key/resource.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@ func (r *keyResource) Read(ctx context.Context, req resource.ReadRequest, resp *
329329
keyResponse, err := r.client.GetKey(ctx, projectId, region, keyRingId, keyId).Execute()
330330
if err != nil {
331331
var oapiErr *oapierror.GenericOpenAPIError
332-
ok := errors.As(err, &oapiErr)
333-
if ok && oapiErr.StatusCode == http.StatusNotFound {
332+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
334333
resp.State.RemoveResource(ctx)
335334
return
336335
}
@@ -375,8 +374,8 @@ func (r *keyResource) Delete(ctx context.Context, req resource.DeleteRequest, re
375374

376375
err := r.client.DeleteKey(ctx, projectId, region, keyRingId, keyId).Execute()
377376
if err != nil {
378-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
379-
if ok && oapiErr.StatusCode == http.StatusNotFound {
377+
var oapiErr *oapierror.GenericOpenAPIError
378+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
380379
return
381380
}
382381
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting key", fmt.Sprintf("Calling API: %v", err))

stackit/internal/services/kms/wrapping-key/resource.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ func (r *wrappingKeyResource) Read(ctx context.Context, request resource.ReadReq
335335
wrappingKeyResponse, err := r.client.GetWrappingKey(ctx, projectId, region, keyRingId, wrappingKeyId).Execute()
336336
if err != nil {
337337
var oapiErr *oapierror.GenericOpenAPIError
338-
ok := errors.As(err, &oapiErr)
339-
if ok && oapiErr.StatusCode == http.StatusNotFound {
338+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
340339
response.State.RemoveResource(ctx)
341340
return
342341
}
@@ -381,8 +380,8 @@ func (r *wrappingKeyResource) Delete(ctx context.Context, request resource.Delet
381380

382381
err := r.client.DeleteWrappingKey(ctx, projectId, region, keyRingId, wrappingKeyId).Execute()
383382
if err != nil {
384-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
385-
if ok && oapiErr.StatusCode == http.StatusNotFound {
383+
var oapiErr *oapierror.GenericOpenAPIError
384+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
386385
return
387386
}
388387
core.LogAndAddError(ctx, &response.Diagnostics, "Error deleting wrapping key", fmt.Sprintf("Calling API: %v", err))

stackit/internal/services/logme/credential/resource.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package logme
22

33
import (
4+
"errors"
45
"context"
56
"fmt"
67
"net/http"
@@ -236,8 +237,8 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
236237

237238
recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute()
238239
if err != nil {
239-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
240-
if ok && oapiErr.StatusCode == http.StatusNotFound {
240+
var oapiErr *oapierror.GenericOpenAPIError
241+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
241242
resp.State.RemoveResource(ctx)
242243
return
243244
}
@@ -290,8 +291,8 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
290291
// Delete existing record set
291292
err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialId).Execute()
292293
if err != nil {
293-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
294-
if ok && oapiErr.StatusCode == http.StatusNotFound {
294+
var oapiErr *oapierror.GenericOpenAPIError
295+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
295296
return
296297
}
297298
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Calling API: %v", err))

stackit/internal/services/mariadb/credential/resource.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mariadb
22

33
import (
4+
"errors"
45
"context"
56
"fmt"
67
"net/http"
@@ -244,8 +245,8 @@ func (r *credentialResource) Read(ctx context.Context, req resource.ReadRequest,
244245

245246
recordSetResp, err := r.client.GetCredentials(ctx, projectId, instanceId, credentialId).Execute()
246247
if err != nil {
247-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
248-
if ok && oapiErr.StatusCode == http.StatusNotFound {
248+
var oapiErr *oapierror.GenericOpenAPIError
249+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
249250
resp.State.RemoveResource(ctx)
250251
return
251252
}
@@ -298,8 +299,8 @@ func (r *credentialResource) Delete(ctx context.Context, req resource.DeleteRequ
298299
// Delete existing record set
299300
err := r.client.DeleteCredentials(ctx, projectId, instanceId, credentialId).Execute()
300301
if err != nil {
301-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
302-
if ok && oapiErr.StatusCode == http.StatusNotFound {
302+
var oapiErr *oapierror.GenericOpenAPIError
303+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
303304
return
304305
}
305306
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting credential", fmt.Sprintf("Calling API: %v", err))

stackit/internal/services/mongodbflex/user/resource.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mongodbflex
22

33
import (
4+
"errors"
45
"context"
56
"fmt"
67
"net/http"
@@ -312,8 +313,8 @@ func (r *userResource) Read(ctx context.Context, req resource.ReadRequest, resp
312313

313314
recordSetResp, err := r.client.GetUser(ctx, projectId, instanceId, userId, region).Execute()
314315
if err != nil {
315-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
316-
if ok && oapiErr.StatusCode == http.StatusNotFound {
316+
var oapiErr *oapierror.GenericOpenAPIError
317+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
317318
resp.State.RemoveResource(ctx)
318319
return
319320
}
@@ -439,8 +440,8 @@ func (r *userResource) Delete(ctx context.Context, req resource.DeleteRequest, r
439440
// Delete user
440441
err := r.client.DeleteUser(ctx, projectId, instanceId, userId, region).Execute()
441442
if err != nil {
442-
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
443-
if ok && oapiErr.StatusCode == http.StatusNotFound {
443+
var oapiErr *oapierror.GenericOpenAPIError
444+
if errors.As(err, &oapiErr) && oapiErr.StatusCode == http.StatusNotFound {
444445
return
445446
}
446447
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting user", fmt.Sprintf("Calling API: %v", err))

0 commit comments

Comments
 (0)