From fcf3799348b039924e9edfbf73dd861570907d1a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 22 Jul 2026 14:37:23 +0200 Subject: [PATCH] archive: fix breakout error type assertions breakoutError was an interface alias, causing errors.As() to match any non-nil error instead of only archive breakout errors. Replace it with a concrete wrapper type while preserving the existing breakoutError(err) helper. Signed-off-by: Sebastiaan van Stijn --- archive.go | 12 ++++++++---- utils_test.go | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/archive.go b/archive.go index 1630ec9..7d8c201 100644 --- a/archive.go +++ b/archive.go @@ -95,10 +95,14 @@ func NewDefaultArchiver() *Archiver { return &Archiver{Untar: Untar} } -// breakoutError is used to differentiate errors related to breaking out -// When testing archive breakout in the unit tests, this error is expected -// in order for the test to pass. -type breakoutError error +// breakoutErr marks errors caused by archive breakout attempts. +// Unit tests use it to distinguish expected breakout failures from other +// errors. +type breakoutErr struct{ error } + +func breakoutError(err error) error { + return &breakoutErr{error: err} +} const ( AUFSWhiteoutFormat WhiteoutFormat = 0 // AUFSWhiteoutFormat is the default format for whiteouts diff --git a/utils_test.go b/utils_test.go index e6edd1f..f030266 100644 --- a/utils_test.go +++ b/utils_test.go @@ -95,7 +95,8 @@ func testBreakout(untarFn string, tmpdir string, headers []*tar.Header) error { return fmt.Errorf("could not find untar function %q in testUntarFns", untarFn) } if err := untar(dest, reader); err != nil { - if !errors.As(err, new(breakoutError)) { + var boErr *breakoutErr + if !errors.As(err, &boErr) { // If untar returns an error unrelated to an archive breakout, // then consider this an unexpected error and abort. return err