Skip to content

Fix codebase antipatterns: sentinel errors, error wrapping, debug cleanup#83

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/identify-code-antipatterns
Draft

Fix codebase antipatterns: sentinel errors, error wrapping, debug cleanup#83
Copilot wants to merge 2 commits intomasterfrom
copilot/identify-code-antipatterns

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 25, 2026

Sweep of common Go antipatterns across the codebase.

  • Sentinel errors: Extract inline errors.New()/fmt.Errorf() to package-level vars (ErrTunnelClosed, ErrHubConnectionClosed, ErrServeFailed, ErrInvalidPathPrefix, ErrExecutablePath) so callers can use errors.Is()
  • Error wrapping: %v%w in fmt.Errorf calls in pkg/cli/upgrade to preserve error chains
  • Remove bare println(): Five debug println() calls writing to stderr in production with no log-level control
  • Simplify log.Println(fmt.Sprintf(…))log.Printf(…)
  • Fix defer resp.Body.Close() ordering: Moved before io.ReadAll in both agent/config and client/config so the body is closed even if the read fails
  • Dead code removal: Commented-out // log.Println(err), commented-out function blocks, empty error branches
// Before
return nil, fmt.Errorf("tunnel closed")

// After
var ErrTunnelClosed = errors.New("tunnel closed")
// ...
return nil, ErrTunnelClosed

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

… debug cleanup

- Convert bare string errors to package-level sentinel errors (ErrTunnelClosed,
  ErrHubConnectionClosed, ErrServeFailed, ErrInvalidPathPrefix, ErrExecutablePath)
- Fix fmt.Errorf with %v to use %w for proper error chain support
- Remove bare println() debug statements from production code
- Fix log.Println(fmt.Sprintf()) redundancy to use log.Printf() directly
- Fix defer resp.Body.Close() placement (move before io.ReadAll)
- Remove commented-out dead code and simplify empty error blocks
- Clean up unnecessary defer wrapper in session plumbing

Co-authored-by: btwiuse <54848194+btwiuse@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and address antipatterns in the codebase Fix codebase antipatterns: sentinel errors, error wrapping, debug cleanup Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants