mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-25 04:11:46 +00:00
e2e: use error wrapping with %w
The recently introduced failure handling in ExpectNoError depends on error wrapping: if an error prefix gets added with `fmt.Errorf("foo: %v", err)`, then ExpectNoError cannot detect that the root cause is an assertion failure and then will add another useless "unexpected error" prefix and will not dump the additional failure information (currently the backtrace inside the E2E framework). Instead of manually deciding on a case-by-case basis where %w is needed, all error wrapping was updated automatically with sed -i "s/fmt.Errorf\(.*\): '*\(%s\|%v\)'*\",\(.* err)\)/fmt.Errorf\1: %w\",\3/" $(git grep -l 'fmt.Errorf' test/e2e*) This may be unnecessary in some cases, but it's not wrong.
This commit is contained in:
@@ -184,7 +184,7 @@ func waitForDeploymentRevision(ctx context.Context, c clientset.Interface, d *ap
|
||||
return revision == targetRevision, nil
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("error waiting for revision to become %q for deployment %q: %v", targetRevision, d.Name, err)
|
||||
return fmt.Errorf("error waiting for revision to become %q for deployment %q: %w", targetRevision, d.Name, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@@ -100,7 +100,7 @@ func inClusterClientMustWork(ctx context.Context, f *framework.Framework, pod *v
|
||||
numTokens, err := e2eauth.ParseInClusterClientLogs(logs)
|
||||
if err != nil {
|
||||
framework.Logf("Error parsing inclusterclient logs: %v", err)
|
||||
return false, fmt.Errorf("inclusterclient reported an error: %v", err)
|
||||
return false, fmt.Errorf("inclusterclient reported an error: %w", err)
|
||||
}
|
||||
if numTokens == 0 {
|
||||
framework.Logf("No authenticated API calls found")
|
||||
|
@@ -143,7 +143,7 @@ func waitForKubeProxyStaticPodsRunning(ctx context.Context, c clientset.Interfac
|
||||
}
|
||||
|
||||
if err := wait.PollImmediate(5*time.Second, defaultTestTimeout, condition); err != nil {
|
||||
return fmt.Errorf("error waiting for kube-proxy static pods running: %v", err)
|
||||
return fmt.Errorf("error waiting for kube-proxy static pods running: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func waitForKubeProxyStaticPodsDisappear(ctx context.Context, c clientset.Interf
|
||||
}
|
||||
|
||||
if err := wait.PollImmediate(5*time.Second, defaultTestTimeout, condition); err != nil {
|
||||
return fmt.Errorf("error waiting for kube-proxy static pods disappear: %v", err)
|
||||
return fmt.Errorf("error waiting for kube-proxy static pods disappear: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -190,7 +190,7 @@ func waitForKubeProxyDaemonSetRunning(ctx context.Context, f *framework.Framewor
|
||||
}
|
||||
|
||||
if err := wait.PollImmediate(5*time.Second, defaultTestTimeout, condition); err != nil {
|
||||
return fmt.Errorf("error waiting for kube-proxy DaemonSet running: %v", err)
|
||||
return fmt.Errorf("error waiting for kube-proxy DaemonSet running: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -213,7 +213,7 @@ func waitForKubeProxyDaemonSetDisappear(ctx context.Context, c clientset.Interfa
|
||||
}
|
||||
|
||||
if err := wait.PollImmediate(5*time.Second, defaultTestTimeout, condition); err != nil {
|
||||
return fmt.Errorf("error waiting for kube-proxy DaemonSet disappear: %v", err)
|
||||
return fmt.Errorf("error waiting for kube-proxy DaemonSet disappear: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user