fix AR mime-type reader error wrap to preserve errors.Is identity#4932
Open
johnelliott wants to merge 1 commit intomainfrom
Open
fix AR mime-type reader error wrap to preserve errors.Is identity#4932johnelliott wants to merge 1 commit intomainfrom
johnelliott wants to merge 1 commit intomainfrom
Conversation
The wrap at pkg/handlers/ar.go:101 used %v on the inner error returned from newMimeTypeReader, dropping its identity from the errors.Is chain. The reachability path is bufReader.Peek -> io.SectionReader over the deb library reader -> BufferedReadSeeker.ReadAt -> the original io.Reader passed to HandleFile. For HTTP/GCS-backed source readers, parent-context cancellation surfaces as a Read error whose chain satisfies errors.Is(err, context.DeadlineExceeded). The %v strips that inner identity, so isFatal at handlers.go:482 misclassifies the wrapped error as a non-fatal warning. Switch to %w to match the same-shape fix already applied at pkg/handlers/default.go:137 and pkg/handlers/ar.go:109. Blast radius is lower than ar.go:109 because processARFiles checks ctx.Done() at the top of each loop iteration, so the next iteration backstops cancellation. The fix is a symmetry/correctness change that lets isFatal classify the wrapped error against its actual cause. Add a regression test that drives processARFiles directly with a crafted *deb.Ar whose first entry's data section returns the target error from ReadAt. The table covers context.DeadlineExceeded, context.Canceled, and io.ErrUnexpectedEOF (io.EOF is filtered inside newMimeTypeReader and never reaches the wrap site). Each case asserts the outer ErrProcessingWarning wrap is preserved, the inner cause is inspectable via errors.Is, and isFatal classifies based on the inner cause.
76f94e8 to
816029e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Same-shape follow-up to PR #4929. Switch the inner
%vto%watpkg/handlers/ar.go:101so the error returned fromnewMimeTypeReaderstays inspectable viaerrors.Isafter being wrapped withErrProcessingWarning.Why
Reachability re-audit confirms the path:
For source readers backed by HTTP/GCS-style transports, parent-context cancellation surfaces here as a
Readerror whose chain satisfieserrors.Is(err, context.DeadlineExceeded)(orcontext.Canceled). The%vwrap strips that inner identity, soisFatalatpkg/handlers/handlers.go:482falls into theErrProcessingWarningbranch and classifies the cancelled/deadline-exceeded read as a non-fatal warning.Blast radius is lower than the sibling
ar.go:109fix becauseprocessARFileschecksctx.Done()at the top of each loop iteration, so the next iteration catches the cancellation anyway. This change is a symmetry/correctness fix that lets the classifier act on the actual cause rather than the outer warning sentinel.What changed
pkg/handlers/ar.go:101:%v->%won the inner error.pkg/handlers/ar_test.go: regression testTestARHandler_MimeTypeReaderErrPreservesIdentitythat drivesprocessARFilesdirectly with a crafted*deb.Arwhose first entry's data section returns the target error fromReadAt. Table-driven overcontext.DeadlineExceeded,context.Canceled, andio.ErrUnexpectedEOF(io.EOFis filtered insidenewMimeTypeReaderand never reaches the wrap site). Each case asserts the outerErrProcessingWarningwrap is preserved, the inner cause is inspectable viaerrors.Is, andisFatalclassifies based on the inner cause.Test plan
go test ./pkg/handlers/ -count=1passes%vmakes the new test fail onerrors.Is(warnErr, tc.innerErr)andisFatalfor the fatal casesgolangci-lintclean on the changed packageNote
Low Risk
Small error-wrapping change plus targeted tests; behavior change is limited to how AR entry read failures are classified via
errors.Is.Overview
Adjusts AR archive handling to wrap
newMimeTypeReaderfailures with%w(instead of%v), preserving the underlying error in theerrors.Ischain when emittingErrProcessingWarning.Adds a regression test that drives
processARFileswith a crafteddeb.Arreader that injects specificReadAterrors, asserting the inner error remains detectable viaerrors.Isand thatisFatalclassifies context cancellation/deadlines as fatal while treatingio.ErrUnexpectedEOFas non-fatal.Reviewed by Cursor Bugbot for commit 816029e. Bugbot is set up for automated code reviews on this repo. Configure here.