fix: handle errors reading go licenses (#2985)

Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
Keith Zantow
2024-06-24 10:27:03 -04:00
committed by GitHub
parent f5a917a5a2
commit bd1c1d260c
4 changed files with 82 additions and 2 deletions
+1 -1
View File
@@ -87,7 +87,7 @@ func subFs(fsys afero.Fs, subDirs ...string) (afero.Fs, error) {
if errors.Is(err, afero.ErrFileNotFound) {
err = fsys.MkdirAll(dir, dirPermissions)
if err != nil {
return nil, fmt.Errorf("unable to create directory at '%s/%s': %v", dir, strings.Join(subDirs, "/"), err)
return nil, fmt.Errorf("unable to create directory at '%s': %v", dir, err)
}
stat, err = fsys.Stat(dir)
if err != nil {
+12
View File
@@ -1,6 +1,7 @@
package cache
import (
"fmt"
"io"
"net/url"
"os"
@@ -92,3 +93,14 @@ func Test_makeDiskKey(t *testing.T) {
})
}
}
func Test_errors(t *testing.T) {
tmp := t.TempDir()
cache := filepath.Join(tmp, "cache")
// make a non-writable directory
require.NoError(t, os.MkdirAll(cache, 0500|os.ModeDir))
// attempt to make cache in non-writable directory
dir := filepath.Join(cache, "dir")
_, err := NewFromDir(dir, time.Hour)
require.ErrorContains(t, err, fmt.Sprintf("unable to create directory at '%s':", dir))
}