From 5316acd046d2039befd061cd06438ad1f6e78214 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 15 Jan 2025 16:32:59 +0000 Subject: [PATCH] fs: fix confusing "didn't find section in config file" error This change decorates the error with the section name not found which will hopefully save user confusion. Fixes #8170 --- backend/googlephotos/googlephotos_test.go | 3 ++- fs/cache/cache_test.go | 4 ++-- fs/newfs.go | 3 ++- fs/rc/rcserver/rcserver_test.go | 2 +- fstest/fstests/fstests.go | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/backend/googlephotos/googlephotos_test.go b/backend/googlephotos/googlephotos_test.go index cd1e0943f..0eeb99bce 100644 --- a/backend/googlephotos/googlephotos_test.go +++ b/backend/googlephotos/googlephotos_test.go @@ -2,6 +2,7 @@ package googlephotos import ( "context" + "errors" "fmt" "io" "net/http" @@ -35,7 +36,7 @@ func TestIntegration(t *testing.T) { *fstest.RemoteName = "TestGooglePhotos:" } f, err := fs.NewFs(ctx, *fstest.RemoteName) - if err == fs.ErrorNotFoundInConfigFile { + if errors.Is(err, fs.ErrorNotFoundInConfigFile) { t.Skipf("Couldn't create google photos backend - skipping tests: %v", err) } require.NoError(t, err) diff --git a/fs/cache/cache_test.go b/fs/cache/cache_test.go index d9d54fa2e..0448f0244 100644 --- a/fs/cache/cache_test.go +++ b/fs/cache/cache_test.go @@ -131,7 +131,7 @@ func TestPutErr(t *testing.T) { assert.Equal(t, 1, Entries()) fNew, err := GetFn(context.Background(), "mock:/", create) - require.Equal(t, fs.ErrorNotFoundInConfigFile, err) + require.True(t, errors.Is(err, fs.ErrorNotFoundInConfigFile)) require.Equal(t, f, fNew) assert.Equal(t, 1, Entries()) @@ -141,7 +141,7 @@ func TestPutErr(t *testing.T) { PutErr("mock:/file.txt", f, fs.ErrorNotFoundInConfigFile) fNew, err = GetFn(context.Background(), "mock:/file.txt", create) - require.Equal(t, fs.ErrorNotFoundInConfigFile, err) + require.True(t, errors.Is(err, fs.ErrorNotFoundInConfigFile)) require.Equal(t, f, fNew) assert.Equal(t, 1, Entries()) diff --git a/fs/newfs.go b/fs/newfs.go index d59a505a6..f4f7dd346 100644 --- a/fs/newfs.go +++ b/fs/newfs.go @@ -6,6 +6,7 @@ import ( "context" "crypto/md5" "encoding/base64" + "fmt" "os" "path/filepath" "strings" @@ -104,7 +105,7 @@ func ParseRemote(path string) (fsInfo *RegInfo, configName, fsPath string, conne m := ConfigMap("", nil, configName, parsed.Config) fsName, ok = m.Get("type") if !ok { - return nil, "", "", nil, ErrorNotFoundInConfigFile + return nil, "", "", nil, fmt.Errorf("%w (%q)", ErrorNotFoundInConfigFile, configName) } } } else { diff --git a/fs/rc/rcserver/rcserver_test.go b/fs/rc/rcserver/rcserver_test.go index 29738b614..f79a926cf 100644 --- a/fs/rc/rcserver/rcserver_test.go +++ b/fs/rc/rcserver/rcserver_test.go @@ -358,7 +358,7 @@ func TestRemoteServing(t *testing.T) { URL: "[notfoundremote:]/", Status: http.StatusInternalServerError, Expected: `{ - "error": "failed to make Fs: didn't find section in config file", + "error": "failed to make Fs: didn't find section in config file (\"notfoundremote\")", "input": null, "path": "/", "status": 500 diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go index 2e840cd0c..6024177c6 100644 --- a/fstest/fstests/fstests.go +++ b/fstest/fstests/fstests.go @@ -459,7 +459,7 @@ func Run(t *testing.T, opt *Opt) { subRemoteName, subRemoteLeaf, err = fstest.RandomRemoteName(remoteName) require.NoError(t, err) f, err = fs.NewFs(context.Background(), subRemoteName) - if err == fs.ErrorNotFoundInConfigFile { + if errors.Is(err, fs.ErrorNotFoundInConfigFile) { t.Logf("Didn't find %q in config file - skipping tests", remoteName) return }