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

Replace fmt.Errorf with errors.New where possible #2275

Merged
Merged
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
6 changes: 6 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ linters-settings:
govet:
enable:
- nilness
perfsprint:
int-conversion: false
errorf: true
sprintf1: false
strconcat: false
revive:
enable-all-rules: false
rules:
Expand All @@ -32,6 +37,7 @@ linters:
- govet
- loggercheck
- misspell
- perfsprint
- revive
- unconvert

Expand Down
8 changes: 4 additions & 4 deletions cmd/kueuectl/app/create/create_localqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package create

import (
"context"
"fmt"
"errors"

"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -141,13 +141,13 @@ func (o *LocalQueueOptions) Complete(clientGetter util.ClientGetter, cmd *cobra.
// Validate validates required fields are set to support structured generation
func (o *LocalQueueOptions) Validate(ctx context.Context) error {
if len(o.Name) == 0 {
return fmt.Errorf("name must be specified")
return errors.New("name must be specified")
}
if len(o.ClusterQueue) == 0 {
return fmt.Errorf("clusterqueue must be specified")
return errors.New("clusterqueue must be specified")
}
if len(o.Namespace) == 0 {
return fmt.Errorf("namespace must be specified")
return errors.New("namespace must be specified")
}
if !o.IgnoreUnknownCq {
_, err := o.Client.ClusterQueues().Get(ctx, o.UserSpecifiedClusterQueue, metav1.GetOptions{})
Expand Down
4 changes: 2 additions & 2 deletions cmd/kueuectl/app/list/list_clusterqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package list

import (
"context"
"fmt"
"errors"
"io"
"time"

Expand Down Expand Up @@ -139,7 +139,7 @@ func (o *ClusterQueueOptions) Complete(clientGetter util.ClientGetter, cmd *cobr

func (o *ClusterQueueOptions) Validate() error {
if !o.validActiveFlagOptionProvided() {
return fmt.Errorf("only one active flag can be provided")
return errors.New("only one active flag can be provided")
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/kueuectl/app/list/list_localqueue_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package list

import (
"fmt"
"errors"
"io"
"time"

Expand All @@ -40,7 +40,7 @@ func (p *listLocalQueuePrinter) PrintObj(obj runtime.Object, out io.Writer) erro

list, ok := obj.(*v1beta1.LocalQueueList)
if !ok {
return fmt.Errorf("invalid object type")
return errors.New("invalid object type")
}

table := &metav1.Table{
Expand Down
8 changes: 4 additions & 4 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (c *Cache) AddClusterQueue(ctx context.Context, cq *kueue.ClusterQueue) err
defer c.Unlock()

if _, ok := c.clusterQueues[cq.Name]; ok {
return fmt.Errorf("ClusterQueue already exists")
return errors.New("ClusterQueue already exists")
}
cqImpl, err := c.newClusterQueue(cq)
if err != nil {
Expand Down Expand Up @@ -459,7 +459,7 @@ func (c *Cache) UpdateWorkload(oldWl, newWl *kueue.Workload) error {
if workload.HasQuotaReservation(oldWl) {
cq, ok := c.clusterQueues[string(oldWl.Status.Admission.ClusterQueue)]
if !ok {
return fmt.Errorf("old ClusterQueue doesn't exist")
return errors.New("old ClusterQueue doesn't exist")
}
cq.deleteWorkload(oldWl)
}
Expand All @@ -470,7 +470,7 @@ func (c *Cache) UpdateWorkload(oldWl, newWl *kueue.Workload) error {
}
cq, ok := c.clusterQueues[string(newWl.Status.Admission.ClusterQueue)]
if !ok {
return fmt.Errorf("new ClusterQueue doesn't exist")
return errors.New("new ClusterQueue doesn't exist")
}
if c.podsReadyTracking {
c.podsReadyCond.Broadcast()
Expand Down Expand Up @@ -543,7 +543,7 @@ func (c *Cache) ForgetWorkload(w *kueue.Workload) error {
defer c.Unlock()

if _, assumed := c.assumedWorkloads[workload.Key(w)]; !assumed {
return fmt.Errorf("the workload is not assumed")
return errors.New("the workload is not assumed")
}
c.cleanupAssumedState(w)

Expand Down
7 changes: 4 additions & 3 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cache

import (
"context"
"errors"
"fmt"
"testing"

Expand Down Expand Up @@ -1425,7 +1426,7 @@ func TestCacheWorkloadOperations(t *testing.T) {
ClusterQueue: "three",
}).Obj()
if !cache.AddOrUpdateWorkload(w) {
return fmt.Errorf("failed to add workload")
return errors.New("failed to add workload")
}
return nil
},
Expand Down Expand Up @@ -1454,7 +1455,7 @@ func TestCacheWorkloadOperations(t *testing.T) {
ClusterQueue: "one",
}).Obj()
if !cache.AddOrUpdateWorkload(w) {
return fmt.Errorf("failed to add workload")
return errors.New("failed to add workload")
}
return nil
},
Expand Down Expand Up @@ -1876,7 +1877,7 @@ func TestCacheWorkloadOperations(t *testing.T) {

w := workloads[0]
if !cache.AddOrUpdateWorkload(w) {
return fmt.Errorf("failed to add workload")
return errors.New("failed to add workload")
}
return nil
},
Expand Down
3 changes: 1 addition & 2 deletions pkg/cache/clusterqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package cache

import (
"errors"
"fmt"
"math"
"strings"

Expand Down Expand Up @@ -452,7 +451,7 @@ func (c *ClusterQueue) updateWithAdmissionChecks(checks map[string]AdmissionChec
func (c *ClusterQueue) addWorkload(w *kueue.Workload) error {
k := workload.Key(w)
if _, exist := c.Workloads[k]; exist {
return fmt.Errorf("workload already exists in ClusterQueue")
return errors.New("workload already exists in ClusterQueue")
}
wi := workload.NewInfo(w)
c.Workloads[k] = wi
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/jobs/pod/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pod

import (
"context"
"errors"
"fmt"
"slices"

Expand All @@ -20,7 +21,7 @@ import (
)

var (
errFailedRefAPIVersionParse = fmt.Errorf("could not parse single pod OwnerReference APIVersion")
errFailedRefAPIVersionParse = errors.New("could not parse single pod OwnerReference APIVersion")
)

func reconcileRequestForPod(p *corev1.Pod) reconcile.Request {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/jobs/pod/pod_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const (

var (
gvk = corev1.SchemeGroupVersion.WithKind("Pod")
errIncorrectReconcileRequest = fmt.Errorf("event handler error: got a single pod reconcile request for a pod group")
errIncorrectReconcileRequest = errors.New("event handler error: got a single pod reconcile request for a pod group")
errPendingOps = jobframework.UnretryableError("waiting to observe previous operations on pods")
errPodNoSupportKubeVersion = errors.New("pod integration only supported in Kubernetes 1.27 or newer")
errPodGroupLabelsMismatch = errors.New("constructing workload: pods have different label values")
Expand Down Expand Up @@ -299,7 +299,7 @@ func (p *Pod) Run(ctx context.Context, c client.Client, podSetsInfo []podset.Pod
// RunWithPodSetsInfo will inject the node affinity and podSet counts extracting from workload to job and unsuspend it.
func (p *Pod) RunWithPodSetsInfo(_ []podset.PodSetInfo) error {
// Not implemented because this is not called when JobWithCustomRun is implemented.
return fmt.Errorf("RunWithPodSetsInfo is not implemented for the Pod object")
return errors.New("RunWithPodSetsInfo is not implemented for the Pod object")
}

// RestorePodSetsInfo will restore the original node affinity and podSet counts of the job.
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/testing/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package testing

import (
"context"
"errors"
"fmt"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -57,7 +58,7 @@ func CheckLatestEvent(ctx context.Context, k8sClient client.Client,

length := len(events.Items)
if length == 0 {
return false, fmt.Errorf("no events currently exist")
return false, errors.New("no events currently exist")
}

item := events.Items[length-1]
Expand Down