Skip to content

Conversation

@zeek0x
Copy link
Contributor

@zeek0x zeek0x commented Jan 18, 2025

Hi :)

While casually looking through the recover.go code, I noticed some logic that identifies errors by matching strings within the error message. Switching to direct error comparisons can improve the maintainability of the code.

@zeek0x zeek0x force-pushed the refactor/smart-error-comparison branch from d569590 to b9bb8d1 Compare January 19, 2025 03:20
@zeek0x
Copy link
Contributor Author

zeek0x commented Jan 19, 2025

I noticed a missed variable name rename, so I fixed it and force-pushed 🙇

@appleboy appleboy requested a review from Copilot May 21, 2025 00:26
@appleboy
Copy link
Member

Please write unit testing.

@appleboy appleboy added this to the v1.11 milestone May 21, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the panic recovery logic in recovery.go to use direct errors.Is comparisons for broken pipe and connection reset errors instead of substring matching, improving maintainability.

  • Replace substring-based detection of broken connections with errors.Is against syscall.EPIPE and syscall.ECONNRESET.
  • Rename variables for clarity (errrec, brokenPipeisBrokenPipeOrConnReset).
  • Remove deprecated net.OpError branch and add syscall import.
Comments suppressed due to low confidence (2)

recovery.go:61

  • [nitpick] The variable name isBrokenPipeOrConnReset is quite long; consider shortening it (e.g., brokenConn) for readability.
var isBrokenPipeOrConnReset bool

recovery.go:64

  • The errors package is used here but not imported; add import "errors" to the import block to avoid a compile error.
isBrokenPipeOrConnReset = errors.Is(err, syscall.EPIPE) || errors.Is(err, syscall.ECONNRESET)

@zeek0x
Copy link
Contributor Author

zeek0x commented May 28, 2025

@appleboy

Please write unit testing.

There was already a good unit test for this fix, so I changed it to fit better.

@appleboy appleboy requested a review from Copilot May 31, 2025 00:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the recovery logic by switching from string matching to direct error comparisons, improving maintainability and clarity.

  • Updated tests to verify error conditions using syscall.Errno comparisons.
  • Revised the panic recovery handler to compare errors with errors.Is and log accordingly.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
recovery_test.go Updated test assertions to directly compare syscall.Errno error values.
recovery.go Refactored panic recovery logic to compare errors using errors.Is with syscall errors.

@codecov
Copy link

codecov bot commented May 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.87%. Comparing base (3dc1cd6) to head (75b09bd).
⚠️ Report is 190 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4142      +/-   ##
==========================================
- Coverage   99.21%   98.87%   -0.35%     
==========================================
  Files          42       44       +2     
  Lines        3182     3459     +277     
==========================================
+ Hits         3157     3420     +263     
- Misses         17       28      +11     
- Partials        8       11       +3     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags sonic 98.86% <100.00%> (?)
-tags go_json 98.74% <100.00%> (?)
-tags nomsgpack 98.79% <100.00%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.24 98.87% <100.00%> (?)
go-1.25 98.81% <100.00%> (?)
macos-latest 98.81% <100.00%> (-0.40%) ⬇️
ubuntu-latest 98.87% <100.00%> (-0.35%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@zeek0x
Copy link
Contributor Author

zeek0x commented Jun 1, 2025

It looks like coverage dropped because the file got shorter, not because there's more untested code.

@appleboy appleboy modified the milestones: v1.11, v1.12 Jun 21, 2025
@appleboy
Copy link
Member

appleboy commented Oct 5, 2025

Please fix the conflicts.

@zeek0x zeek0x force-pushed the refactor/smart-error-comparison branch from 4732fa7 to 6cfc3cd Compare October 10, 2025 12:57
@zeek0x
Copy link
Contributor Author

zeek0x commented Oct 10, 2025

It looks like coverage dropped because the file got shorter, not because there's more untested code.

Again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants