Skip to content

Commit

Permalink
Use errors.Is()
Browse files Browse the repository at this point in the history
Silence IDE lint warnings
  • Loading branch information
Bryan Venteicher committed Dec 18, 2024
1 parent 9d40af0 commit c549529
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cmd/web-console-validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
"errors"
"flag"
"net/http"
"os"
Expand Down Expand Up @@ -93,7 +94,7 @@ func main() {
}

logger.Info("Starting the web-console validation server", "port", *serverPort, "path", *serverPath)
if err := server.Run(); err != nil && err != http.ErrServerClosed {
if err := server.Run(); err != nil && !errors.Is(err, http.ErrServerClosed) {
logger.Error(err, "Failed to run the web-console validation server")
os.Exit(1)
}
Expand Down
5 changes: 3 additions & 2 deletions controllers/infra/zone/zone_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package zone

import (
"context"
"errors"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -131,7 +132,7 @@ func (r *Reconciler) ReconcileDelete(
},
fmt.Sprintf("%s/%s", obj.Namespace, obj.Name)); err != nil {

if err != watcher.ErrAsyncSignalDisabled {
if !errors.Is(err, watcher.ErrAsyncSignalDisabled) {
return ctrl.Result{}, err
}
}
Expand All @@ -157,7 +158,7 @@ func (r *Reconciler) ReconcileNormal(
},
fmt.Sprintf("%s/%s", obj.Namespace, obj.Name)); err != nil {

if err != watcher.ErrAsyncSignalDisabled {
if !errors.Is(err, watcher.ErrAsyncSignalDisabled) {
return ctrl.Result{}, err
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,10 @@ func getIsDefaultVMClassController(ctx context.Context) bool {
// ignoredCreateErr is written this way in order to illustrate coverage more
// accurately.
func ignoredCreateErr(err error) bool {
if err == providers.ErrDuplicateCreate {
if errors.Is(err, providers.ErrDuplicateCreate) {
return true
}
if err == providers.ErrTooManyCreates {
if errors.Is(err, providers.ErrTooManyCreates) {
return true
}
return false
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/vsphere/vm/power_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func doAndWaitOnSoftPowerOp(
defer cancel()

if err := waitForPowerStateFn(ctx, desiredPowerState); err != nil {
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return 0, fmt.Errorf("timed out waiting for power state %s", desiredPowerState)
}
return 0, fmt.Errorf("failed to wait for power state %s %w", desiredPowerState, err)
Expand Down Expand Up @@ -606,7 +606,7 @@ func doAndWaitOnSoftRestart(
defer cancel()

if err := powerOpFn(ctx); err != nil {
if ctx.Err() == context.DeadlineExceeded {
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
return 0, errors.New("timed out while soft restarting vm")
}
return 0, fmt.Errorf("failed to soft restart vm %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/vmconfig/crypto/crypto_reconciler_pre.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func (r reconciler) reconcileUpdateDefaultKeyProvider(
}

func setConditionAndReturnErr(args reconcileArgs, err error, r Reason) error {
if err == ErrInvalidKeyProvider || err == ErrInvalidKeyID {
if errors.Is(err, ErrInvalidKeyProvider) || errors.Is(err, ErrInvalidKeyID) {
r = ReasonEncryptionClassInvalid
} else if apierrors.IsNotFound(err) {
r = ReasonEncryptionClassNotFound
Expand Down
3 changes: 2 additions & 1 deletion webhooks/virtualmachine/mutation/virtualmachine_mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package mutation
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"reflect"
Expand Down Expand Up @@ -596,7 +597,7 @@ func SetDefaultEncryptionClass(
k8sClient,
vm.Namespace)
if err != nil {
if err == kubeutil.ErrNoDefaultEncryptionClass {
if errors.Is(err, kubeutil.ErrNoDefaultEncryptionClass) {
return false, nil
}
return false, err
Expand Down

0 comments on commit c549529

Please sign in to comment.