From 25b7766673867d2a9ac32fde6cb0d719f04b2953 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 18 Oct 2020 02:29:06 +0100 Subject: [PATCH] When handling errors in storageHandler check underlying error (#13178) Unfortunately there was a mistake in #13164 which fails to handle os.PathError wrapping an os.ErrNotExist Signed-off-by: Andrew Thornton Co-authored-by: techknowlogick --- modules/storage/minio.go | 2 +- routers/routes/routes.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/storage/minio.go b/modules/storage/minio.go index 4a2819de5ef..0e0cb3690da 100644 --- a/modules/storage/minio.go +++ b/modules/storage/minio.go @@ -32,7 +32,7 @@ type minioObject struct { func (m *minioObject) Stat() (os.FileInfo, error) { oi, err := m.Object.Stat() if err != nil { - return nil, err + return nil, convertMinioErr(err) } return &minioFileInfo{oi}, nil diff --git a/routers/routes/routes.go b/routers/routes/routes.go index adda9198576..9f7ff277cf0 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -7,6 +7,7 @@ package routes import ( "bytes" "encoding/gob" + "errors" "fmt" "io" "net/http" @@ -127,7 +128,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor rPath := strings.TrimPrefix(req.RequestURI, "/"+prefix) u, err := objStore.URL(rPath, path.Base(rPath)) if err != nil { - if err == os.ErrNotExist { + if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) { log.Warn("Unable to find %s %s", prefix, rPath) ctx.Error(404, "file not found") return @@ -160,7 +161,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor //If we have matched and access to release or issue fr, err := objStore.Open(rPath) if err != nil { - if err == os.ErrNotExist { + if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) { log.Warn("Unable to find %s %s", prefix, rPath) ctx.Error(404, "file not found") return