Skip to content

Conversation

@mohamedfawas
Copy link
Contributor

Summary

This PR standardizes error wrapping in the CLI by replacing %v with %w
only in cases where an existing error is being wrapped.

This ensures proper error chaining and enables the use of errors.Is and
errors.As as intended by Go best practices.


What was changed

  • Updated fmt.Errorf(... %v, err) to fmt.Errorf(... %w, err) in CLI code paths
  • Left formatting-only cases (strings, slices, validation errors) unchanged
  • No functional changes beyond improved error propagation

Why this change

The CLI currently mixes %v and %w for error handling.
Using %w consistently:

  • Preserves the original error chain
  • Improves debuggability
  • Aligns with Go’s recommended error-wrapping patterns

Fixes #3040.


Testing

  • Changes are limited to error formatting
  • No behavior changes were introduced

Signed-off-by: mohamedfawas <fawastmh@gmail.com>
@github-actions github-actions bot added the size/M Medium PR: 300-599 lines changed label Dec 18, 2025
@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

❌ Patch coverage is 22.85714% with 108 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@414dcff). Learn more about missing BASE report.
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/container/docker/client.go 10.52% 17 Missing ⚠️
pkg/api/server.go 0.00% 9 Missing ⚠️
pkg/workloads/manager.go 43.75% 9 Missing ⚠️
pkg/container/docker/squid.go 0.00% 8 Missing ⚠️
pkg/runner/retriever/retriever.go 0.00% 7 Missing ⚠️
pkg/runner/runner.go 0.00% 7 Missing ⚠️
...lpha1/virtualmcpcompositetooldefinition_webhook.go 45.45% 6 Missing ⚠️
pkg/client/manager.go 0.00% 6 Missing ⚠️
pkg/container/images/docker.go 0.00% 6 Missing ⚠️
pkg/container/kubernetes/client.go 0.00% 6 Missing ⚠️
... and 13 more
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3094   +/-   ##
=======================================
  Coverage        ?   57.11%           
=======================================
  Files           ?      341           
  Lines           ?    33950           
  Branches        ?        0           
=======================================
  Hits            ?    19390           
  Misses          ?    12951           
  Partials        ?     1609           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Dec 22, 2025
Copy link
Member

@eleftherias eleftherias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @mohamedfawas, I noticed some %v remained. I left comments below.

@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Dec 22, 2025
Co-authored-by: Eleftheria Stein-Kousathana <eleftheria.kousathana@gmail.com>
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Dec 22, 2025
@mohamedfawas
Copy link
Contributor Author

I ran the failing test locally:

go test ./pkg/workloads/statuses -run TestRuntimeStatusManager_GetWorkload -v

and it passes consistently on my end.

Since this PR only changes error formatting and doesn’t touch workload/status logic, this looks like a CI-only or flaky failure.

Happy to help investigate further or rerun CI if needed—please let me know how you’d like me to proceed.

@eleftherias eleftherias merged commit 262e711 into stacklok:main Dec 22, 2025
39 of 40 checks passed
@eleftherias
Copy link
Member

@mohamedfawas I was able to rerun the CI and the test passed. Thanks for your contribution!

@mohamedfawas mohamedfawas deleted the fix/error-wrapping-cli branch December 23, 2025 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardize on error wrapping in CLI

2 participants