refactor: replace direct error comparisons with errors.Is#460
refactor: replace direct error comparisons with errors.Is#460pixel365 wants to merge 2 commits intosipeed:mainfrom
Conversation
Improves correctness when working with wrapped errors
nikolasdehor
left a comment
There was a problem hiding this comment.
The production code changes are all correct — errors.Is is the idiomatic pattern for wrapped error checking since Go 1.13.
However, I found two reversed argument bugs in the test files:
-
pkg/providers/error_classifier_test.go:errors.Is(inner, fe.Unwrap())should beerrors.Is(fe.Unwrap(), inner). The first argument is the error chain to search, the second is the target. -
pkg/tools/message_test.go:errors.Is(sendErr, result.Err)should beerrors.Is(result.Err, sendErr). We're asking "doesresult.ErrmatchsendErr?", not the reverse.
Both happen to work by coincidence (since the objects are equal), but the semantics are wrong and could mask real bugs if the code is later modified to wrap errors.
Also: the copy -> cp rename in codex_provider.go is unrelated — consider a separate commit or mention in description.
- Fix reversed arguments in errors.Is calls in tests - Revert cp -> copy rename in codex_provider.go to keep PR focused
|
@nikolasdehor |
nikolasdehor
left a comment
There was a problem hiding this comment.
Correct and idiomatic. All replacements are appropriate:
context.Canceledandcontext.DeadlineExceededcan be wrapped by libraries, soerrors.Isis the right approach.http.ErrServerClosed— same reasoning.syscall.EBUSY—syscall.Errnoimplementserror, soerrors.Isworks here too, thoughErrnovalues are typically not wrapped. Still correct and future-proof.
The test updates (fallback_test.go, message_test.go, error_classifier_test.go) are consistent with the production code changes.
LGTM.
📝 Description
Replaced direct error comparisons (
err == someErr) witherrors.Is.This ensures correct behavior when errors are wrapped and aligns the codebase with idiomatic Go error handling practices.
No functional changes intended — logic remains the same, comparison mechanism improved.
🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
N/A
📚 Technical Context (Skip for Docs)
==comparison does not work reliably with wrapped errors.errors.Isproperly unwraps and matches sentinel errors.🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
No behavior changes observed. Existing tests pass.
☑️ Checklist