Replace uses of os.IsExist and os.IsNotExist with errors.Is.

The former don't properly unwrap errors.
This commit is contained in:
Juliusz Chroboczek committed 2024-04-14 13:34:32 +02:00
1 parent 68887f13d5
commit 3409f5a27f
10 files changed
+21 -19

No files matched your search

+3 -2
View File
@@ -5,6 +5,7 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
@@ -170,7 +171,7 @@ func apiGroupHandler(w http.ResponseWriter, r *http.Request, pth string) {
return
} else if r.Method == "PUT" {
etag, err := group.GetDescriptionTag(g)
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
err = nil
etag = ""
} else if err != nil {
@@ -299,7 +300,7 @@ func usersHandler(w http.ResponseWriter, r *http.Request, g, pth string) {
return
} else if r.Method == "PUT" {
etag, err := group.GetUserTag(g, username)
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
etag = ""
err = nil
} else if err != nil {
+1 -1
View File
@@ -291,7 +291,7 @@ func TestApi(t *testing.T) {
}
_, err = group.GetDescription("test")
if !os.IsNotExist(err) {
if !errors.Is(err, os.ErrNotExist) {
t.Errorf("Group exists after delete")
}
}
+2 -2
View File
@@ -120,7 +120,7 @@ func notFound(w http.ResponseWriter) {
var ErrIsDirectory = errors.New("is a directory")
func httpError(w http.ResponseWriter, err error) {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
notFound(w)
return
}
@@ -235,7 +235,7 @@ func (fh *fileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ff, err := fh.root.Open(index)
if err != nil {
// return 403 if index.html doesn't exist
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
http.Error(w, "Forbidden", http.StatusForbidden)
return
}