mirror of https://github.com/knative/pkg.git
Add errorlint and fix all existing issues (#1855)
This commit is contained in:
parent
b520ee28a9
commit
565516e224
|
@ -9,6 +9,7 @@ run:
|
|||
linters:
|
||||
enable:
|
||||
- asciicheck
|
||||
- errorlint
|
||||
- golint
|
||||
- gosec
|
||||
- prealloc
|
||||
|
|
|
@ -97,7 +97,7 @@ func TestEnqueueInformerFactoryWithFailure(t *testing.T) {
|
|||
Resource: "caches",
|
||||
}
|
||||
inf, _, got := eif.Get(context.Background(), gvr)
|
||||
if got != want {
|
||||
if !errors.Is(got, want) {
|
||||
t.Fatalf("Get() = %v, wanted %v", got, want)
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ func TestInvalidResource(t *testing.T) {
|
|||
|
||||
_, _, got := tif.Get(context.Background(), SchemeGroupVersion.WithResource("resources"))
|
||||
|
||||
if got != errTest {
|
||||
if !errors.Is(got, errTest) {
|
||||
t.Errorf("Error = %v, want: %v", got, errTest)
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ func TestAsStructuredWatcherNestedError(t *testing.T) {
|
|||
wf := duck.AsStructuredWatcher(context.Background(), nwf, &duckv1alpha1.AddressableType{})
|
||||
|
||||
_, got := wf(metav1.ListOptions{})
|
||||
if got != want {
|
||||
if !errors.Is(got, want) {
|
||||
t.Errorf("WatchFunc() = %v, wanted %v", got, want)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package duck
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"encoding/json"
|
||||
|
@ -83,7 +84,7 @@ func TestFromUnstructuredFooable(t *testing.T) {
|
|||
t.Log("Marshalled:", string(raw))
|
||||
|
||||
got := Foo{}
|
||||
if err := FromUnstructured(tc.in, &got); err != tc.wantError {
|
||||
if err := FromUnstructured(tc.in, &got); !errors.Is(err, tc.wantError) {
|
||||
t.Fatal("FromUnstructured() =", err)
|
||||
}
|
||||
|
||||
|
@ -145,7 +146,7 @@ func TestToUnstructured(t *testing.T) {
|
|||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, err := ToUnstructured(tc.in)
|
||||
if err != tc.wantError {
|
||||
if !errors.Is(err, tc.wantError) {
|
||||
t.Fatal("ToUnstructured() =", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -79,17 +79,17 @@ func roundTrip(instance interface{}, input, output Populatable) error {
|
|||
// Serialize the input to JSON and deserialize that into the provided instance
|
||||
// of the type that we are checking.
|
||||
if before, err := json.Marshal(input); err != nil {
|
||||
return fmt.Errorf("error serializing duck type %T error: %s", input, err)
|
||||
return fmt.Errorf("error serializing duck type %T error: %w", input, err)
|
||||
} else if err := json.Unmarshal(before, instance); err != nil {
|
||||
return fmt.Errorf("error deserializing duck type %T into %T error: %s", input, instance, err)
|
||||
return fmt.Errorf("error deserializing duck type %T into %T error: %w", input, instance, err)
|
||||
}
|
||||
|
||||
// Serialize the instance we are checking to JSON and deserialize that into the
|
||||
// output resource.
|
||||
if after, err := json.Marshal(instance); err != nil {
|
||||
return fmt.Errorf("error serializing %T error: %s", instance, err)
|
||||
return fmt.Errorf("error serializing %T error: %w", instance, err)
|
||||
} else if err := json.Unmarshal(after, output); err != nil {
|
||||
return fmt.Errorf("error deserializing %T into duck type %T error: %s", instance, output, err)
|
||||
return fmt.Errorf("error deserializing %T into duck type %T error: %w", instance, output, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -199,7 +199,9 @@ func TestStoreFailedFirstConversionCrashes(t *testing.T) {
|
|||
cmd := exec.Command(os.Args[0], fmt.Sprintf("-test.run=%s", t.Name()))
|
||||
cmd.Env = append(os.Environ(), "CRASH=1")
|
||||
err := cmd.Run()
|
||||
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
|
||||
|
||||
var errExit *exec.ExitError
|
||||
if errors.As(err, &errExit) && !errExit.Success() {
|
||||
return
|
||||
}
|
||||
t.Fatal("process should have exited with status 1 - err", err)
|
||||
|
|
|
@ -582,6 +582,7 @@ func IsPermanentError(err error) bool {
|
|||
// Is implements the Is() interface of error. It returns whether the target
|
||||
// error can be treated as equivalent to a permanentError.
|
||||
func (permanentError) Is(target error) bool {
|
||||
//nolint: errorlint // This check is actually fine.
|
||||
_, ok := target.(permanentError)
|
||||
return ok
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ func buildGraph(importpaths ...string) (graph, error) {
|
|||
func CheckNoDependency(ip string, banned []string) error {
|
||||
g, err := buildGraph(ip)
|
||||
if err != nil {
|
||||
return fmt.Errorf("buildGraph(queue) = %v", err)
|
||||
return fmt.Errorf("buildGraph(queue) = %w", err)
|
||||
}
|
||||
for _, dip := range banned {
|
||||
if g.contains(dip) {
|
||||
|
@ -136,7 +136,7 @@ func AssertNoDependency(t *testing.T, banned map[string][]string) {
|
|||
func CheckOnlyDependencies(ip string, allowed map[string]struct{}) error {
|
||||
g, err := buildGraph(ip)
|
||||
if err != nil {
|
||||
return fmt.Errorf("buildGraph(queue) = %v", err)
|
||||
return fmt.Errorf("buildGraph(queue) = %w", err)
|
||||
}
|
||||
for _, name := range g.order() {
|
||||
if _, ok := allowed[name]; !ok {
|
||||
|
|
|
@ -18,6 +18,7 @@ package sharedmain
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -241,7 +242,7 @@ func MainWithConfig(ctx context.Context, component string, cfg *rest.Config, cto
|
|||
|
||||
profilingServer.Shutdown(context.Background())
|
||||
// Don't forward ErrServerClosed as that indicates we're already shutting down.
|
||||
if err := eg.Wait(); err != nil && err != http.ErrServerClosed {
|
||||
if err := eg.Wait(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
logger.Errorw("Error while running server", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ func (cs *configMapKVStore) Get(ctx context.Context, key string, value interface
|
|||
}
|
||||
err := json.Unmarshal([]byte(v), value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to Unmarshal %q: %v", v, err)
|
||||
return fmt.Errorf("failed to Unmarshal %q: %w", v, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ func (cs *configMapKVStore) Get(ctx context.Context, key string, value interface
|
|||
func (cs *configMapKVStore) Set(ctx context.Context, key string, value interface{}) error {
|
||||
bytes, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to Marshal: %v", err)
|
||||
return fmt.Errorf("failed to Marshal: %w", err)
|
||||
}
|
||||
cs.data[key] = string(bytes)
|
||||
return nil
|
||||
|
|
|
@ -212,7 +212,7 @@ func UpdateLevelFromConfigMap(logger *zap.SugaredLogger, atomicLevel zap.AtomicL
|
|||
// reset to global level
|
||||
loggingCfg, err := zapConfigFromJSON(config.LoggingConfig)
|
||||
switch {
|
||||
case err == errEmptyLoggerConfig:
|
||||
case errors.Is(err, errEmptyLoggerConfig):
|
||||
level = zap.NewAtomicLevel().Level()
|
||||
case err != nil:
|
||||
logger.With(zap.Error(err)).Errorf("Failed to parse logger configuration. "+
|
||||
|
|
|
@ -85,7 +85,7 @@ func getOpenCensusSecret(component string, lister SecretFetcher) (*corev1.Secret
|
|||
secret, err = lister("opencensus")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to fetch opencensus secret for %q, cannot use requireSecure=true: %+v", component, err)
|
||||
return nil, fmt.Errorf("unable to fetch opencensus secret for %q, cannot use requireSecure=true: %w", component, err)
|
||||
}
|
||||
|
||||
return secret, nil
|
||||
|
|
|
@ -18,6 +18,7 @@ package metrics
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
@ -739,7 +740,7 @@ func (oc *openCensusFake) Export(stream ocmetrics.MetricsService_ExportServer) e
|
|||
metricSeen := false
|
||||
for {
|
||||
in, err := stream.Recv()
|
||||
if err == io.EOF {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
@ -363,7 +363,7 @@ func getStackdriverSecret(ctx context.Context, secretFetcher SecretFetcher) (*co
|
|||
}
|
||||
|
||||
if secErr != nil {
|
||||
return nil, fmt.Errorf("error getting Secret [%v] in namespace [%v]: %v", secretName, secretNamespace, secErr)
|
||||
return nil, fmt.Errorf("error getting Secret [%v] in namespace [%v]: %w", secretName, secretNamespace, secErr)
|
||||
}
|
||||
|
||||
return sec, nil
|
||||
|
|
|
@ -18,6 +18,7 @@ package prober
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -222,7 +223,7 @@ func TestDoAsyncTimeout(t *testing.T) {
|
|||
if done {
|
||||
t.Errorf("done was true")
|
||||
}
|
||||
if err != wait.ErrWaitTimeout {
|
||||
if !errors.Is(err, wait.ErrWaitTimeout) {
|
||||
t.Error("Unexpected error =", err)
|
||||
}
|
||||
wch <- arg
|
||||
|
|
|
@ -18,6 +18,7 @@ package network
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
@ -76,7 +77,8 @@ func dialBackOffHelper(ctx context.Context, network, address string, bo wait.Bac
|
|||
for {
|
||||
c, err := dialer.DialContext(ctx, network, address)
|
||||
if err != nil {
|
||||
if err, ok := err.(net.Error); ok && err.Timeout() {
|
||||
var errNet net.Error
|
||||
if errors.As(err, &errNet) && errNet.Timeout() {
|
||||
if bo.Steps < 1 {
|
||||
break
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ func TestParallelismWithErrors(t *testing.T) {
|
|||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
// Make all unexpected errors wait.
|
||||
if err != errExpected {
|
||||
if !errors.Is(err, errExpected) {
|
||||
<-barrier
|
||||
}
|
||||
return err
|
||||
|
@ -193,7 +193,7 @@ func TestParallelismWithErrors(t *testing.T) {
|
|||
// remaining work.
|
||||
wg.Wait()
|
||||
|
||||
if err := p.Wait(); err != errExpected {
|
||||
if err := p.Wait(); !errors.Is(err, errExpected) {
|
||||
t.Errorf("Wait() = %v, wanted %v", err, errExpected)
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,7 @@ func TestErrorCancelsContext(t *testing.T) {
|
|||
case <-time.After(100 * time.Millisecond):
|
||||
t.Error("ctx is not canceled due to the first error")
|
||||
}
|
||||
if err := pool.Wait(); err != want {
|
||||
if err := pool.Wait(); !errors.Is(err, want) {
|
||||
t.Fatalf("pool.Wait() = %v, want: %v", err, want)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,8 @@ var _ error = (*ReconcilerEvent)(nil)
|
|||
// Is returns if the target error is a ReconcilerEvent type checking that
|
||||
// EventType and Reason match.
|
||||
func (e *ReconcilerEvent) Is(target error) bool {
|
||||
if t, ok := target.(*ReconcilerEvent); ok {
|
||||
var t *ReconcilerEvent
|
||||
if errors.As(target, &t) {
|
||||
if t != nil && t.EventType == e.EventType && t.Reason == e.Reason {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ func TestRetryUpdateConflicts(t *testing.T) {
|
|||
return test.returns[i]
|
||||
})
|
||||
|
||||
if got != test.want {
|
||||
if !errors.Is(got, test.want) {
|
||||
t.Errorf("RetryUpdateConflicts() = %v, want %v", got, test.want)
|
||||
}
|
||||
if attempts != test.wantAttempts {
|
||||
|
@ -125,7 +125,7 @@ func TestRetryTestErrors(t *testing.T) {
|
|||
return test.returns[i]
|
||||
})
|
||||
|
||||
if got != test.want {
|
||||
if !errors.Is(got, test.want) {
|
||||
t.Errorf("RetryTestErrors() = %v, want %v", got, test.want)
|
||||
}
|
||||
if attempts != test.wantAttempts {
|
||||
|
|
|
@ -18,6 +18,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -143,8 +144,10 @@ func runCommandsInParallel(cmdLines ...string) (string, error) {
|
|||
// getErrorCode extracts the exit code of an *ExitError type
|
||||
func getErrorCode(err error) int {
|
||||
errorCode := defaultErrCode
|
||||
if exitError, ok := err.(*exec.ExitError); ok {
|
||||
errorCode = exitError.ExitCode()
|
||||
|
||||
var errExit *exec.ExitError
|
||||
if errors.As(err, &errExit) {
|
||||
errorCode = errExit.ExitCode()
|
||||
}
|
||||
return errorCode
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
@ -65,7 +66,8 @@ func TestRunCommand(t *testing.T) {
|
|||
t.Fatalf("Expect %q but actual is %q", c.expectedOutput, out)
|
||||
}
|
||||
if err != nil {
|
||||
if ce, ok := err.(*CommandLineError); ok {
|
||||
var ce *CommandLineError
|
||||
if errors.As(err, &ce) {
|
||||
if ce.ErrorCode != c.expectedErrorCode {
|
||||
t.Fatalf("Expect to get error code %d but got %d", c.expectedErrorCode, ce.ErrorCode)
|
||||
}
|
||||
|
@ -130,7 +132,8 @@ func TestRunCommands(t *testing.T) {
|
|||
t.Fatalf("Expect %q but actual is %q", c.expectedOutput, out)
|
||||
}
|
||||
if err != nil {
|
||||
if ce, ok := err.(*CommandLineError); ok {
|
||||
var ce *CommandLineError
|
||||
if errors.As(err, &ce) {
|
||||
if ce.ErrorCode != c.expectedErrorCode {
|
||||
t.Fatalf("Expect to get error code %d but got %d", c.expectedErrorCode, ce.ErrorCode)
|
||||
}
|
||||
|
|
|
@ -136,11 +136,11 @@ func (g *GCSClient) getObjectsAttrs(ctx context.Context, bucketName, storagePath
|
|||
|
||||
for {
|
||||
attrs, err := it.Next()
|
||||
if err == iterator.Done {
|
||||
if errors.Is(err, iterator.Done) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error iterating: %v", err)
|
||||
return nil, fmt.Errorf("error iterating: %w", err)
|
||||
}
|
||||
allAttrs = append(allAttrs, attrs)
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package mock
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -379,7 +380,7 @@ func TestNewStorageBucket(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
t.Run(tt.testname, func(t *testing.T) {
|
||||
err := mockClient.NewStorageBucket(ctx, tt.bkt, tt.projectName)
|
||||
if (tt.err == nil || err == nil) && err != tt.err {
|
||||
if (tt.err == nil || err == nil) && !errors.Is(err, tt.err) {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
} else if (tt.err != nil && err != nil) && tt.err.Error() != err.Error() {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
|
@ -441,7 +442,7 @@ func TestDeleteStorageBucket(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
t.Run(tt.testname, func(t *testing.T) {
|
||||
err := mockClient.DeleteStorageBucket(ctx, tt.bkt, tt.force)
|
||||
if (tt.err == nil || err == nil) && err != tt.err {
|
||||
if (tt.err == nil || err == nil) && !errors.Is(err, tt.err) {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
} else if (tt.err != nil && err != nil) && tt.err.Error() != err.Error() {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
|
@ -568,7 +569,7 @@ func TestListChildrenFiles(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
t.Run(tt.testname, func(t *testing.T) {
|
||||
children, err := mockClient.ListChildrenFiles(ctx, tt.bkt, tt.dir)
|
||||
if (tt.err == nil || err == nil) && err != tt.err {
|
||||
if (tt.err == nil || err == nil) && !errors.Is(err, tt.err) {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
} else if (tt.err != nil && err != nil) && tt.err.Error() != err.Error() {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
|
@ -634,7 +635,7 @@ func TestListDirectChildren(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
t.Run(tt.testname, func(t *testing.T) {
|
||||
children, err := mockClient.ListDirectChildren(ctx, tt.bkt, tt.dir)
|
||||
if (tt.err == nil || err == nil) && err != tt.err {
|
||||
if (tt.err == nil || err == nil) && !errors.Is(err, tt.err) {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
} else if (tt.err != nil && err != nil) && tt.err.Error() != err.Error() {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
|
@ -690,7 +691,7 @@ func TestAttrObject(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
t.Run(tt.testname, func(t *testing.T) {
|
||||
objAttr, err := mockClient.AttrObject(ctx, tt.bkt, tt.objpath)
|
||||
if (tt.err == nil || err == nil) && err != tt.err {
|
||||
if (tt.err == nil || err == nil) && !errors.Is(err, tt.err) {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
} else if (tt.err != nil && err != nil) && tt.err.Error() != err.Error() {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
|
@ -781,7 +782,7 @@ func TestCopyObject(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
t.Run(tt.testname, func(t *testing.T) {
|
||||
err := mockClient.CopyObject(ctx, tt.srcBkt, tt.srcObjPath, tt.dstBkt, tt.dstObjPath)
|
||||
if (tt.err == nil || err == nil) && err != tt.err {
|
||||
if (tt.err == nil || err == nil) && !errors.Is(err, tt.err) {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
} else if (tt.err != nil && err != nil) && tt.err.Error() != err.Error() {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
|
@ -843,7 +844,7 @@ func TestReadObject(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
t.Run(tt.testname, func(t *testing.T) {
|
||||
objContent, err := mockClient.ReadObject(ctx, tt.bkt, tt.objpath)
|
||||
if (tt.err == nil || err == nil) && err != tt.err {
|
||||
if (tt.err == nil || err == nil) && !errors.Is(err, tt.err) {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
} else if (tt.err != nil && err != nil) && tt.err.Error() != err.Error() {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
|
@ -899,7 +900,7 @@ func TestWriteObject(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
t.Run(tt.testname, func(t *testing.T) {
|
||||
n, err := mockClient.WriteObject(ctx, tt.bkt, tt.objpath, tt.content)
|
||||
if (tt.err == nil || err == nil) && err != tt.err {
|
||||
if (tt.err == nil || err == nil) && !errors.Is(err, tt.err) {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
} else if (tt.err != nil && err != nil) && tt.err.Error() != err.Error() {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
|
@ -955,7 +956,7 @@ func TestDeleteObject(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
t.Run(tt.testname, func(t *testing.T) {
|
||||
err := mockClient.DeleteObject(ctx, tt.bkt, tt.objpath)
|
||||
if (tt.err == nil || err == nil) && err != tt.err {
|
||||
if (tt.err == nil || err == nil) && !errors.Is(err, tt.err) {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
} else if (tt.err != nil && err != nil) && tt.err.Error() != err.Error() {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
|
@ -1013,7 +1014,7 @@ func TestDownload(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
t.Run(tt.testname, func(t *testing.T) {
|
||||
err := mockClient.Download(ctx, tt.bkt, tt.objPath, file)
|
||||
if (tt.err == nil || err == nil) && err != tt.err {
|
||||
if (tt.err == nil || err == nil) && !errors.Is(err, tt.err) {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
} else if (tt.err != nil && err != nil) && tt.err.Error() != err.Error() {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
|
@ -1076,7 +1077,7 @@ func TestUpload(t *testing.T) {
|
|||
for _, tt := range testCases {
|
||||
t.Run(tt.testname, func(t *testing.T) {
|
||||
err := mockClient.Upload(ctx, tt.bkt, tt.objPath, file)
|
||||
if (tt.err == nil || err == nil) && err != tt.err {
|
||||
if (tt.err == nil || err == nil) && !errors.Is(err, tt.err) {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
} else if (tt.err != nil && err != nil) && tt.err.Error() != err.Error() {
|
||||
t.Fatalf("expected error %v, got error %v", tt.err, err)
|
||||
|
|
|
@ -20,6 +20,7 @@ package ghutil
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
@ -119,10 +120,11 @@ func (gc *GithubClient) retry(message string, maxRetries int, call func() (*gith
|
|||
if resp, err = call(); nil == err {
|
||||
return resp, nil
|
||||
}
|
||||
switch err := err.(type) {
|
||||
case *github.RateLimitError:
|
||||
gc.waitForRateReset(&err.Rate)
|
||||
default:
|
||||
|
||||
var errRateLimit *github.RateLimitError
|
||||
if errors.As(err, &errRateLimit) {
|
||||
gc.waitForRateReset(&errRateLimit.Rate)
|
||||
} else {
|
||||
return resp, err
|
||||
}
|
||||
log.Printf("error %s: %v. Will retry.\n", message, err)
|
||||
|
|
|
@ -45,7 +45,7 @@ type sdkClient struct {
|
|||
func NewSDKClient(opts ...option.ClientOption) (SDKOperations, error) {
|
||||
containerService, err := container.NewService(context.Background(), opts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create container service: '%v'", err)
|
||||
return nil, fmt.Errorf("failed to create container service: %w", err)
|
||||
}
|
||||
return &sdkClient{containerService}, nil
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ func (gsc *sdkClient) ListClustersInProject(project string) ([]*container.Cluste
|
|||
projectFullPath := fmt.Sprintf("projects/%s/locations/-", project)
|
||||
resp, err := gsc.Projects.Locations.Clusters.List(projectFullPath).Do()
|
||||
if err != nil {
|
||||
return clusters, fmt.Errorf("failed to list clusters under project %s: %v", project, err)
|
||||
return clusters, fmt.Errorf("failed to list clusters under project %s: %w", project, err)
|
||||
}
|
||||
return resp.Clusters, nil
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ func (e Env) PromoteFromEnv(envVars ...string) error {
|
|||
for _, env := range envVars {
|
||||
v := os.Getenv(env)
|
||||
if v == "" {
|
||||
err = fmt.Errorf("environment variable %q is not set; %v", env, err)
|
||||
err = fmt.Errorf("environment variable %q is not set; %w", env, err)
|
||||
} else {
|
||||
e[env] = v
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ func TestTLoggerInternals(legacy *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run("errorWithRuntimeCheck "+tt.testName, func(t *TLogger) {
|
||||
e, s, i := t.errorWithRuntimeCheck(tt.inputs...)
|
||||
if e != tt.expectedError {
|
||||
if !errors.Is(e, tt.expectedError) {
|
||||
t.Error("error did not match", "got", e, "want", tt.expectedError)
|
||||
}
|
||||
if s != tt.expectedString {
|
||||
|
|
|
@ -51,6 +51,7 @@ func getBenchmark() (*mpb.BenchmarkInfo, error) {
|
|||
if koerr != nil {
|
||||
data, err = ioutil.ReadFile(filepath.Join(configMako, env+".config"))
|
||||
if err != nil {
|
||||
//nolint: errorlint // It's fine not to wrap here.
|
||||
return nil, fmt.Errorf("cannot load both from kodata and from config mako config map: %s, %s", koerr.Error(), err.Error())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
@ -158,7 +159,7 @@ func main() {
|
|||
m.HandleFunc("/close", func(writer http.ResponseWriter, request *http.Request) {
|
||||
s.Shutdown(context.Background())
|
||||
})
|
||||
if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
if err := s.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println("Successfully served the results")
|
||||
|
|
|
@ -19,13 +19,20 @@ limitations under the License.
|
|||
package spoof
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func isTCPTimeout(e error) bool {
|
||||
err, ok := e.(net.Error)
|
||||
return err != nil && ok && err.Timeout()
|
||||
func isTCPTimeout(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var errNet net.Error
|
||||
if !errors.As(err, &errNet) {
|
||||
return false
|
||||
}
|
||||
return errNet.Timeout()
|
||||
}
|
||||
|
||||
func isDNSError(err error) bool {
|
||||
|
|
|
@ -237,7 +237,8 @@ func (sc *SpoofingClient) logZipkinTrace(spoofResp *Response) {
|
|||
|
||||
json, err := zipkin.JSONTrace(traceID /* We don't know the expected number of spans */, -1, 5*time.Second)
|
||||
if err != nil {
|
||||
if _, ok := err.(*zipkin.TimeoutError); !ok {
|
||||
var errTimeout *zipkin.TimeoutError
|
||||
if !errors.As(err, &errTimeout) {
|
||||
sc.Logf("Error getting zipkin trace: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ func IsProw() bool {
|
|||
func GetRepoName() (string, error) {
|
||||
out, err := StandardExec("git", "rev-parse", "--show-toplevel")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed git rev-parse --show-toplevel: '%v'", err)
|
||||
return "", fmt.Errorf("failed git rev-parse --show-toplevel: %w", err)
|
||||
}
|
||||
return strings.TrimSpace(path.Base(string(out))), nil
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package common
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -68,7 +67,7 @@ func TestGetRepoName(t *testing.T) {
|
|||
"a/b/c/", nil, "c", nil,
|
||||
}, {
|
||||
// Git error
|
||||
"", fmt.Errorf("git error"), "", fmt.Errorf("failed git rev-parse --show-toplevel: 'git error'"),
|
||||
"", fmt.Errorf("git error"), "", fmt.Errorf("failed git rev-parse --show-toplevel: git error"),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -85,7 +84,7 @@ func TestGetRepoName(t *testing.T) {
|
|||
}
|
||||
|
||||
out, err := GetRepoName()
|
||||
if data.expOut != out || !reflect.DeepEqual(err, data.expErr) {
|
||||
if data.expOut != out || (err != nil && err.Error() != data.expErr.Error()) {
|
||||
t.Errorf("testing getting repo name with:\n\tmocked git output: '%s'\n\tmocked git err: '%v'\nwant: out - '%s', err - '%v'\ngot: out - '%s', err - '%v'",
|
||||
data.out, data.err, data.expOut, data.expErr, out, err)
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ func (gc *GKECluster) checkEnvironment() error {
|
|||
if (gc.Request.Project == "" || gc.Request.Project == project) && (gc.Request.ClusterName == "" || gc.Request.ClusterName == clusterName) {
|
||||
client, err := gc.newGKEClient(project)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed creating the GKE client: '%v'", err)
|
||||
return fmt.Errorf("failed creating the GKE client: %w", err)
|
||||
}
|
||||
cluster, err := client.GetCluster(project, region, zone, clusterName)
|
||||
if err != nil {
|
||||
|
|
|
@ -44,7 +44,7 @@ func getResourceName(rt ResourceType) (string, error) {
|
|||
var resName string
|
||||
repoName, err := common.GetRepoName()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed getting reponame for forming resource name: '%v'", err)
|
||||
return "", fmt.Errorf("failed getting reponame for forming resource name: %w", err)
|
||||
}
|
||||
resName = fmt.Sprintf("k%s-%s", repoName, string(rt))
|
||||
if common.IsProw() {
|
||||
|
|
|
@ -92,7 +92,7 @@ func Create(o *options.RequestWrapper) (*clm.GKECluster, error) {
|
|||
clusterOps := gkeClient.Setup(o.Request)
|
||||
gkeOps := clusterOps.(*clm.GKECluster)
|
||||
if err := gkeOps.Acquire(); err != nil || gkeOps.Cluster == nil {
|
||||
return nil, fmt.Errorf("failed acquiring GKE cluster: '%v'", err)
|
||||
return nil, fmt.Errorf("failed acquiring GKE cluster: %w", err)
|
||||
}
|
||||
|
||||
// At this point we should have a cluster ready to run test. Need to save
|
||||
|
@ -104,10 +104,10 @@ func Create(o *options.RequestWrapper) (*clm.GKECluster, error) {
|
|||
// TODO(chaodaiG): this probably should also be part of clustermanager lib
|
||||
if out, err := common.StandardExec("gcloud", "beta", "container", "clusters", "get-credentials",
|
||||
gkeOps.Cluster.Name, "--region", gkeOps.Cluster.Location, "--project", gkeOps.Project); err != nil {
|
||||
return nil, fmt.Errorf("failed connecting to cluster: %q, '%v'", out, err)
|
||||
return nil, fmt.Errorf("failed connecting to cluster: %q, %w", out, err)
|
||||
}
|
||||
if out, err := common.StandardExec("gcloud", "config", "set", "project", gkeOps.Project); err != nil {
|
||||
return nil, fmt.Errorf("failed setting gcloud: %q, '%v'", out, err)
|
||||
return nil, fmt.Errorf("failed setting gcloud: %q, %w", out, err)
|
||||
}
|
||||
|
||||
return gkeOps, nil
|
||||
|
|
|
@ -33,12 +33,12 @@ func Delete(o *options.RequestWrapper) error {
|
|||
clusterOps := gkeClient.Setup(o.Request)
|
||||
gkeOps := clusterOps.(*clm.GKECluster)
|
||||
if err := gkeOps.Acquire(); err != nil || gkeOps.Cluster == nil {
|
||||
return fmt.Errorf("failed identifying cluster for cleanup: '%v'", err)
|
||||
return fmt.Errorf("failed identifying cluster for cleanup: %w", err)
|
||||
}
|
||||
log.Printf("Identified project %q and cluster %q for removal", gkeOps.Project, gkeOps.Cluster.Name)
|
||||
var err error
|
||||
if err = gkeOps.Delete(); err != nil {
|
||||
return fmt.Errorf("failed deleting cluster: '%v'", err)
|
||||
return fmt.Errorf("failed deleting cluster: %w", err)
|
||||
}
|
||||
// Unset context with best effort. The first command only unsets current
|
||||
// context, but doesn't delete the entry from kubeconfig, and should return it's
|
||||
|
|
|
@ -57,7 +57,7 @@ func TestOpenCensusTraceApplyConfigFailingConfigOption(t *testing.T) {
|
|||
}
|
||||
return nil
|
||||
})
|
||||
if err := oct.ApplyConfig(&config.Config{}); err != coErr {
|
||||
if err := oct.ApplyConfig(&config.Config{}); !errors.Is(err, coErr) {
|
||||
t.Errorf("Expected error not seen. Got %q. Want %q", err, coErr)
|
||||
}
|
||||
if err := oct.Finish(); err != nil {
|
||||
|
@ -81,7 +81,7 @@ func TestOpenCensusTraceFinishFailingConfigOption(t *testing.T) {
|
|||
if err := oct.ApplyConfig(&config.Config{}); err != nil {
|
||||
t.Errorf("Unexpected error Applying Config: %q", err)
|
||||
}
|
||||
if err := oct.Finish(); err != coErr {
|
||||
if err := oct.Finish(); !errors.Is(err, coErr) {
|
||||
t.Errorf("Expected error not seen. Got %q. Want %q", err, coErr)
|
||||
}
|
||||
if err := oct.Finish(); err != nil {
|
||||
|
|
|
@ -209,7 +209,7 @@ func (wh *Webhook) Run(stop <-chan struct{}) error {
|
|||
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
eg.Go(func() error {
|
||||
if err := server.ListenAndServeTLS("", ""); err != nil && err != http.ErrServerClosed {
|
||||
if err := server.ListenAndServeTLS("", ""); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
logger.Errorw("ListenAndServeTLS for admission webhook returned error", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ func TestSendErrorOnNoConnection(t *testing.T) {
|
|||
conn := &ManagedConnection{}
|
||||
got := conn.Send("test")
|
||||
|
||||
if got != want {
|
||||
if !errors.Is(got, want) {
|
||||
t.Fatalf("Wanted error to be %v, but it was %v.", want, got)
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ func TestStatusOnNoConnection(t *testing.T) {
|
|||
conn := &ManagedConnection{}
|
||||
got := conn.Status()
|
||||
|
||||
if got != want {
|
||||
if !errors.Is(got, want) {
|
||||
t.Fatalf("Wanted error to be %v, but it was %v.", want, got)
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ func TestConnectLoopIsStopped(t *testing.T) {
|
|||
|
||||
select {
|
||||
case err := <-errorChan:
|
||||
if err != errShuttingDown {
|
||||
if !errors.Is(err, errShuttingDown) {
|
||||
t.Errorf("Wrong 'connect' error, got %v, want %v", err, errShuttingDown)
|
||||
}
|
||||
case <-time.After(propagationTimeout):
|
||||
|
@ -316,7 +316,7 @@ func TestKeepaliveLoopIsStopped(t *testing.T) {
|
|||
|
||||
select {
|
||||
case err := <-errorChan:
|
||||
if err != errShuttingDown {
|
||||
if !errors.Is(err, errShuttingDown) {
|
||||
t.Errorf("Wrong 'keepalive' error, got %v, want %v", err, errShuttingDown)
|
||||
}
|
||||
case <-time.After(propagationTimeout):
|
||||
|
|
Loading…
Reference in New Issue