fix nested archive handler error wraps to preserve errors.Is identity#4931
Open
johnelliott wants to merge 3 commits into
Open
fix nested archive handler error wraps to preserve errors.Is identity#4931johnelliott wants to merge 3 commits into
johnelliott wants to merge 3 commits into
Conversation
Contributor
Author
|
Question on the test assertions: any reason these use The testify helper produces a better diagnostic on failure (it prints the actual error chain), and we already import |
The non-archive content paths in pkg/handlers/ar.go:109 and pkg/handlers/rpm.go:120 wrapped the inner error returned from handleNonArchiveContent with %v, dropping its identity from the errors.Is chain. Because handleNonArchiveContent can return ctx.Err() (context.Canceled or context.DeadlineExceeded) when its CancellableWrite fails, isFatal at handlers.go:425 then misclassified those cancelled or deadline-exceeded conditions as non-fatal warnings and continued processing. Switch both wraps to %w so the inner cause is preserved alongside ErrProcessingWarning, matching the same-shape fix already applied to the canonical wrap at default.go:137. Add regression tests for both handlers that exercise the production wrap path via an injected chunk reader that cancels the parent context before its chunk is written, which forces handleNonArchiveContent to return context.Canceled and processARFiles / processRPMFiles to wrap it. The tests assert the outer ErrProcessingWarning wrap is preserved, the inner cancellation cause is inspectable via errors.Is, and isFatal classifies the result as fatal.
f822d37 to
e7d7f6f
Compare
rosecodym
reviewed
Apr 29, 2026
- Drop stdctx alias on the stdlib context import; alias trufflehog's pkg/context as trContext to match the package idiom. - Replace assert.True(t, errors.Is(...)) with assert.ErrorIs to get better diagnostics on failure.
alafiand
reviewed
Apr 29, 2026
Address review nit on PR #4931: line numbers in regression-test docstrings will go stale as the file evolves. Reference the symbolic shape instead (dataOrErrChan ErrProcessingWarning send in processARFiles/processRPMFiles' handleNonArchiveContent error path).
3 tasks
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
Two same-shape
%verror wraps in nested archive handlers drop the innererror's identity from the
errors.Ischain, causing theisFatalclassifier inpkg/handlers/handlers.goto misclassifycancellation and deadline-exceeded conditions as non-fatal warnings.
This is the identical bug fixed for the canonical chunk-reader wrap in
PR #4929.
Affected sites:
pkg/handlers/ar.go:109pkg/handlers/rpm.go:120Both wrap the return value of
handleNonArchiveContent, which can bectx.Err()(context.Canceled/context.DeadlineExceeded) when itsinternal
CancellableWritefails. The wrapped error feedsisFatalatpkg/handlers/handlers.go:425. With%v, neithererrors.Is(err, context.Canceled)norerrors.Is(err, context.DeadlineExceeded)matches, so the classifierfalls through to the
ErrProcessingWarningcase and processingcontinues despite a fatal cause.
Fix
Change the inner
%vto%win both wraps, matching the shape used byPR #4929. Multi-
%win a singlefmt.Errorfis supported on Go1.20+; this repo is on Go 1.24.
Behavior change
Cancelled or deadline-exceeded processing inside an AR or RPM nested
archive now correctly terminates instead of being logged as a warning
and continuing.
Tests
Added a regression test for each handler:
TestARHandler_NonArchiveErrPreservesIdentityinar_test.goTestRPMHandler_NonArchiveErrPreservesIdentityinrpm_test.goEach test injects a chunk reader that cancels the parent context before
delivering its chunk, forcing
handleNonArchiveContent'sCancellableWriteto returncontext.Canceled, which the surroundinghandler wraps. The tests assert the outer
ErrProcessingWarningwrap ispreserved, the inner cancellation cause is inspectable via
errors.Is, andisFatalclassifies the wrapped error as fatal.Verified the tests catch the regression by reverting just the wrap
fix: both tests fail on
errors.Is(err, context.Canceled)andisFatal(err), then pass again once the fix is reapplied.Test plan
go test ./pkg/handlers/ -count=1passesgo vet ./pkg/handlers/clean%w->%v-> tests fail; reapply -> tests passNote
Low Risk
Small, targeted change to error wrapping plus new tests; behavior only changes for cancellation/deadline paths in AR/RPM processing and is unlikely to impact normal success flows.
Overview
Fixes AR and RPM nested archive handlers to wrap
handleNonArchiveContentfailures with%w(instead of%v) while still tagging them withErrProcessingWarning, preservingerrors.Isidentity for underlying causes likecontext.Canceled/context.DeadlineExceeded.Adds regression tests (
TestARHandler_NonArchiveErrPreservesIdentity,TestRPMHandler_NonArchiveErrPreservesIdentity) that inject a cancelling chunk reader and assert both the outer warning wrap and the inner cancellation cause remain detectable and are classified as fatal byisFatal.Reviewed by Cursor Bugbot for commit 7b66333. Bugbot is set up for automated code reviews on this repo. Configure here.