From a6b6a938deced0d99475cc07620b3cc8005eeee8 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Tue, 5 Dec 2023 13:57:08 -0600 Subject: [PATCH] blobstorage: Improve mkdirall error (#13271) --- beacon-chain/db/filesystem/blob.go | 2 +- beacon-chain/db/filesystem/blob_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/beacon-chain/db/filesystem/blob.go b/beacon-chain/db/filesystem/blob.go index 1c178e188..8cbe6e877 100644 --- a/beacon-chain/db/filesystem/blob.go +++ b/beacon-chain/db/filesystem/blob.go @@ -36,7 +36,7 @@ const ( func NewBlobStorage(base string) (*BlobStorage, error) { base = path.Clean(base) if err := file.MkdirAll(base); err != nil { - return nil, err + return nil, fmt.Errorf("failed to create blob storage at %s: %w", base, err) } fs := afero.NewBasePathFs(afero.NewOsFs(), base) return &BlobStorage{fs: fs}, nil diff --git a/beacon-chain/db/filesystem/blob_test.go b/beacon-chain/db/filesystem/blob_test.go index ae895ed5d..8ca55f60f 100644 --- a/beacon-chain/db/filesystem/blob_test.go +++ b/beacon-chain/db/filesystem/blob_test.go @@ -2,6 +2,8 @@ package filesystem import ( "bytes" + "os" + "path" "testing" "github.com/ethereum/go-ethereum/common/hexutil" @@ -129,3 +131,14 @@ func TestBlobStorageDelete(t *testing.T) { // Deleting a non-existent root does not return an error. require.NoError(t, bs.Delete(bytesutil.ToBytes32([]byte{0x1}))) } + +func TestNewBlobStorage(t *testing.T) { + _, err := NewBlobStorage(path.Join(t.TempDir(), "good")) + require.NoError(t, err) + + // If directory already exists with improper permissions, expect a wrapped err message. + fp := path.Join(t.TempDir(), "bad") + require.NoError(t, os.Mkdir(fp, 0777)) + _, err = NewBlobStorage(fp) + require.ErrorContains(t, "failed to create blob storage", err) +}