Skip to content

Commit

Permalink
fix: remove empty error wrapping (#1185)
Browse files Browse the repository at this point in the history
# Description

This pull request includes changes to improve error handling in the
`pkg/plugin/hnsstats/vfp_counters_windows.go` file. The most important
changes include modifying the `getVfpPortCountersRaw` and `listvPorts`
functions to ensure they return appropriate error messages when command
execution fails.

Error handling improvements:

*
[`pkg/plugin/hnsstats/vfp_counters_windows.go`](diffhunk://#diff-0999dc1285d058391926e8093f7a02cea33a0e2d3cd1ba29bfd1b153900d23c2L156-R170):
Modified the `getVfpPortCountersRaw` function to return an empty string
and wrapped error message when command execution fails.
*
[`pkg/plugin/hnsstats/vfp_counters_windows.go`](diffhunk://#diff-0999dc1285d058391926e8093f7a02cea33a0e2d3cd1ba29bfd1b153900d23c2L156-R170):
Modified the `listvPorts` function to return the command output and
wrapped error message when command execution fails.


## Checklist

- [X] I have read the [contributing
documentation](https://retina.sh/docs/contributing).
- [X] I signed and signed-off the commits (`git commit -S -s ...`). See
[this
documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
on signing commits.
- [X] I have correctly attributed the author(s) of the code.
- [ ] I have tested the changes locally.
- [X] I have followed the project's style guidelines.
- [X] I have updated the documentation, if necessary.
- [X] I have added tests, if applicable.

## Screenshots (if applicable) or Testing Completed

Please add any relevant screenshots or GIFs to showcase the changes
made.

## Additional Notes

Add any additional notes or context about the pull request here.

---

Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more
information on how to contribute to this project.

---------

Signed-off-by: Ritwik Ranjan <[email protected]>
Co-authored-by: Evan Baker <[email protected]>
  • Loading branch information
ritwikranjan and rbtr authored Jan 7, 2025
1 parent f574448 commit b08a1bc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/plugin/hnsstats/vfp_counters_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,20 @@ func getVfpPortCountersRaw(portGUID string) (string, error) {
cmd := exec.Command("cmd", "/c", vfpCmd)
out, err := cmd.Output()

return string(out), errors.Wrap(err, "errored while running vfpctrl /get-port-counter")
if err != nil {
return "", errors.Wrap(err, "errored while running vfpctrl /get-port-counter")
}
return string(out), nil
}

// TODO: Remove this once Resources.Allocators.EndpointPortGuid gets added to hcsshim Endpoint struct
// Lists all vSwitch ports
func listvPorts() ([]byte, error) {
out, err := exec.Command("cmd", "/c", "vfpctrl /list-vmswitch-port").CombinedOutput()
return out, errors.Wrap(err, "errored while running vfpctrl /list-vmswitch-port")
if err != nil {
return out, errors.Wrap(err, "errored while running vfpctrl /list-vmswitch-port")
}
return out, nil
}

// TODO: Remove this once Resources.Allocators.EndpointPortGuid gets added to hcsshim Endpoint struct
Expand Down

0 comments on commit b08a1bc

Please sign in to comment.