Skip to content

Commit 010af54

Browse files
committed
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 <github@gone.nl>
1 parent 4b90d95 commit 010af54

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

archive.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,14 @@ func NewDefaultArchiver() *Archiver {
9595
return &Archiver{Untar: Untar}
9696
}
9797

98-
// breakoutError is used to differentiate errors related to breaking out
99-
// When testing archive breakout in the unit tests, this error is expected
100-
// in order for the test to pass.
101-
type breakoutError error
98+
// breakoutErr marks errors caused by archive breakout attempts.
99+
// Unit tests use it to distinguish expected breakout failures from other
100+
// errors.
101+
type breakoutErr struct{ error }
102+
103+
func breakoutError(err error) error {
104+
return &breakoutErr{error: err}
105+
}
102106

103107
const (
104108
AUFSWhiteoutFormat WhiteoutFormat = 0 // AUFSWhiteoutFormat is the default format for whiteouts

utils_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ func testBreakout(untarFn string, tmpdir string, headers []*tar.Header) error {
8888
return fmt.Errorf("could not find untar function %q in testUntarFns", untarFn)
8989
}
9090
if err := untar(dest, reader); err != nil {
91-
if !errors.As(err, new(breakoutError)) {
91+
var boErr *breakoutErr
92+
if !errors.As(err, &boErr) {
9293
// If untar returns an error unrelated to an archive breakout,
9394
// then consider this an unexpected error and abort.
9495
return err

0 commit comments

Comments
 (0)