blobstorage: Improve mkdirall error (#13271)

This commit is contained in:
Preston Van Loon 2023-12-05 13:57:08 -06:00 committed by GitHub
parent c78d698d89
commit a6b6a938de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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)
}