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

Wrap nested errors #1558

Merged
merged 1 commit into from
Jan 23, 2024
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
16 changes: 8 additions & 8 deletions pkg/nfd-master/nfd-master.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
if !m.config.NoPublish {
err := m.updateMasterNode()
if err != nil {
return fmt.Errorf("failed to update master node: %v", err)
return fmt.Errorf("failed to update master node: %w", err)

Check warning on line 254 in pkg/nfd-master/nfd-master.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/nfd-master.go#L254

Added line #L254 was not covered by tests
}
}

Expand Down Expand Up @@ -368,7 +368,7 @@
// Create server listening for TCP connections
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", m.args.Port))
if err != nil {
errChan <- fmt.Errorf("failed to listen: %v", err)
errChan <- fmt.Errorf("failed to listen: %w", err)

Check warning on line 371 in pkg/nfd-master/nfd-master.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/nfd-master.go#L371

Added line #L371 was not covered by tests
return
}

Expand Down Expand Up @@ -414,7 +414,7 @@

case err := <-grpcErr:
if err != nil {
errChan <- fmt.Errorf("gRPC server exited with an error: %v", err)
errChan <- fmt.Errorf("gRPC server exited with an error: %w", err)

Check warning on line 417 in pkg/nfd-master/nfd-master.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/nfd-master.go#L417

Added line #L417 was not covered by tests
}
klog.InfoS("gRPC server stopped")
}
Expand Down Expand Up @@ -552,7 +552,7 @@
"/metadata/annotations")
err = m.apihelper.PatchNode(cli, node.Name, p)
if err != nil {
return fmt.Errorf("failed to patch node annotations: %v", err)
return fmt.Errorf("failed to patch node annotations: %w", err)
}

return nil
Expand Down Expand Up @@ -951,7 +951,7 @@
if len(patches) > 0 {
err = m.apihelper.PatchNode(cli, node.Name, patches)
if err != nil {
return fmt.Errorf("error while patching node object: %v", err)
return fmt.Errorf("error while patching node object: %w", err)

Check warning on line 954 in pkg/nfd-master/nfd-master.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/nfd-master.go#L954

Added line #L954 was not covered by tests
}
klog.V(1).InfoS("patched node annotations for taints", "nodeName", nodeName)
}
Expand Down Expand Up @@ -1112,13 +1112,13 @@
statusPatches := m.createExtendedResourcePatches(node, extendedResources)
err = m.apihelper.PatchNodeStatus(cli, node.Name, statusPatches)
if err != nil {
return fmt.Errorf("error while patching extended resources: %v", err)
return fmt.Errorf("error while patching extended resources: %w", err)

Check warning on line 1115 in pkg/nfd-master/nfd-master.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/nfd-master.go#L1115

Added line #L1115 was not covered by tests
}

// Patch the node object in the apiserver
err = m.apihelper.PatchNode(cli, node.Name, patches)
if err != nil {
return fmt.Errorf("error while patching node object: %v", err)
return fmt.Errorf("error while patching node object: %w", err)
}

if len(patches) > 0 || len(statusPatches) > 0 {
Expand Down Expand Up @@ -1235,7 +1235,7 @@

// Parse config overrides
if err := yaml.Unmarshal([]byte(overrides), c); err != nil {
return fmt.Errorf("failed to parse -options: %s", err)
return fmt.Errorf("failed to parse -options: %w", err)

Check warning on line 1238 in pkg/nfd-master/nfd-master.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/nfd-master.go#L1238

Added line #L1238 was not covered by tests
}
if m.args.Overrides.NoPublish != nil {
c.NoPublish = *m.args.Overrides.NoPublish
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcemonitor/podresourcesscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
hasDevice := hasDevice(podResource)
isWatchable, isIntegralGuaranteed, err := resMon.isWatchable(podResource.GetNamespace(), podResource.GetName(), hasDevice)
if err != nil {
return ScanResponse{}, fmt.Errorf("checking if pod in a namespace is watchable, namespace:%v, pod name %v: %v", podResource.GetNamespace(), podResource.GetName(), err)
return ScanResponse{}, fmt.Errorf("checking if pod in a namespace is watchable, namespace:%v, pod name %v: %w", podResource.GetNamespace(), podResource.GetName(), err)

Check warning on line 156 in pkg/resourcemonitor/podresourcesscanner.go

View check run for this annotation

Codecov / codecov/patch

pkg/resourcemonitor/podresourcesscanner.go#L156

Added line #L156 was not covered by tests
}
if !isWatchable {
continue
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/fswatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@
func (w *FsWatcher) initWatcher() error {
if w.Watcher != nil {
if err := w.Watcher.Close(); err != nil {
return fmt.Errorf("failed to close fsnotify watcher: %v", err)
return fmt.Errorf("failed to close fsnotify watcher: %w", err)

Check warning on line 70 in pkg/utils/fswatcher.go

View check run for this annotation

Codecov / codecov/patch

pkg/utils/fswatcher.go#L70

Added line #L70 was not covered by tests
}
}
w.paths = make(map[string]struct{})

watcher, err := fsnotify.NewWatcher()
if err != nil {
w.Watcher = nil
return fmt.Errorf("failed to create fsnotify watcher: %v", err)
return fmt.Errorf("failed to create fsnotify watcher: %w", err)

Check warning on line 78 in pkg/utils/fswatcher.go

View check run for this annotation

Codecov / codecov/patch

pkg/utils/fswatcher.go#L78

Added line #L78 was not covered by tests
}
w.Watcher = watcher

Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/klog/klog.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
v = a.DefValue()
}
if err := a.SetFromConfig(v); err != nil {
return fmt.Errorf("failed to set logger option klog.%s = %v: %v", k, v, err)
return fmt.Errorf("failed to set logger option klog.%s = %v: %w", k, v, err)

Check warning on line 55 in pkg/utils/klog/klog.go

View check run for this annotation

Codecov / codecov/patch

pkg/utils/klog/klog.go#L55

Added line #L55 was not covered by tests
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
// Load cert for authenticating this server
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
return fmt.Errorf("failed to load server certificate: %v", err)
return fmt.Errorf("failed to load server certificate: %w", err)

Check warning on line 50 in pkg/utils/tls.go

View check run for this annotation

Codecov / codecov/patch

pkg/utils/tls.go#L50

Added line #L50 was not covered by tests
}
// Load CA cert for client cert verification
caCert, err := os.ReadFile(caFile)
if err != nil {
return fmt.Errorf("failed to read root certificate file: %v", err)
return fmt.Errorf("failed to read root certificate file: %w", err)

Check warning on line 55 in pkg/utils/tls.go

View check run for this annotation

Codecov / codecov/patch

pkg/utils/tls.go#L55

Added line #L55 was not covered by tests
}
caPool := x509.NewCertPool()
if ok := caPool.AppendCertsFromPEM(caCert); !ok {
Expand Down
2 changes: 1 addition & 1 deletion source/cpu/power_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

effectiveBaseFreq, err := strconv.Atoi(strings.TrimSpace(string(data)))
if err != nil {
return false, fmt.Errorf("non-integer value of %q: %v", filePath, err)
return false, fmt.Errorf("non-integer value of %q: %w", filePath, err)

Check warning on line 72 in source/cpu/power_amd64.go

View check run for this annotation

Codecov / codecov/patch

source/cpu/power_amd64.go#L72

Added line #L72 was not covered by tests
}

// Sanity check: Return an error (we don't have enough information to
Expand Down
4 changes: 2 additions & 2 deletions source/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
klog.InfoS("hook directory does not exist", "path", hookDir)
return features, labels, nil
}
return features, labels, fmt.Errorf("unable to access %v: %v", hookDir, err)
return features, labels, fmt.Errorf("unable to access %v: %w", hookDir, err)

Check warning on line 294 in source/local/local.go

View check run for this annotation

Codecov / codecov/patch

source/local/local.go#L294

Added line #L294 was not covered by tests
}
if len(files) > 0 {
klog.InfoS("hooks are DEPRECATED since v0.12.0 and support will be removed in a future release; use feature files instead")
Expand Down Expand Up @@ -382,7 +382,7 @@
klog.InfoS("features directory does not exist", "path", featureFilesDir)
return features, labels, nil
}
return features, labels, fmt.Errorf("unable to access %v: %v", featureFilesDir, err)
return features, labels, fmt.Errorf("unable to access %v: %w", featureFilesDir, err)

Check warning on line 385 in source/local/local.go

View check run for this annotation

Codecov / codecov/patch

source/local/local.go#L385

Added line #L385 was not covered by tests
}

for _, file := range files {
Expand Down
4 changes: 2 additions & 2 deletions source/pci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
func readSinglePciAttribute(devPath string, attrName string) (string, error) {
data, err := os.ReadFile(filepath.Join(devPath, attrName))
if err != nil {
return "", fmt.Errorf("failed to read device attribute %s: %v", attrName, err)
return "", fmt.Errorf("failed to read device attribute %s: %w", attrName, err)

Check warning on line 39 in source/pci/utils.go

View check run for this annotation

Codecov / codecov/patch

source/pci/utils.go#L39

Added line #L39 was not covered by tests
}
// Strip whitespace and '0x' prefix
attrVal := strings.TrimSpace(strings.TrimPrefix(string(data), "0x"))
Expand All @@ -55,7 +55,7 @@
for _, attr := range mandatoryDevAttrs {
attrVal, err := readSinglePciAttribute(devPath, attr)
if err != nil {
return nil, fmt.Errorf("failed to read device %s: %s", attr, err)
return nil, fmt.Errorf("failed to read device %s: %w", attr, err)

Check warning on line 58 in source/pci/utils.go

View check run for this annotation

Codecov / codecov/patch

source/pci/utils.go#L58

Added line #L58 was not covered by tests
}
attrs[attr] = attrVal
}
Expand Down
2 changes: 1 addition & 1 deletion source/usb/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
func readSingleUsbSysfsAttribute(path string) (string, error) {
data, err := os.ReadFile(path)
if err != nil {
return "", fmt.Errorf("failed to read device attribute %s: %v", filepath.Base(path), err)
return "", fmt.Errorf("failed to read device attribute %s: %w", filepath.Base(path), err)

Check warning on line 46 in source/usb/utils.go

View check run for this annotation

Codecov / codecov/patch

source/usb/utils.go#L46

Added line #L46 was not covered by tests
}

attrVal := strings.TrimSpace(string(data))
Expand Down