Skip to content

Commit

Permalink
Be more defensive above checking the atomicValue type
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanvanburen committed Nov 1, 2024
1 parent 2515c42 commit 1a41b94
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions private/pkg/storage/storageos/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/bufbuild/buf/private/pkg/normalpath"
"github.com/bufbuild/buf/private/pkg/storage"
"github.com/bufbuild/buf/private/pkg/storage/storageutil"
"github.com/bufbuild/buf/private/pkg/syserror"
)

// errNotDir is the error returned if a path is not a directory.
Expand Down Expand Up @@ -416,10 +417,14 @@ func (e *onceError) Store(err error) {

// Load loads the stored error.
func (e *onceError) Load() error {
err, ok := e.err.Load().(error)
if !ok {
atomicValue := e.err.Load()
if atomicValue == nil {
return nil
}
err, ok := atomicValue.(error)
if !ok {
return syserror.Newf("expected error but got %T", atomicValue)
}
return err
}

Expand Down

0 comments on commit 1a41b94

Please sign in to comment.