From 45db94c0e1aaff123c3060c59429e064cc4fc1b4 Mon Sep 17 00:00:00 2001 From: Matt Dainty Date: Sat, 11 Feb 2023 15:02:39 +0000 Subject: [PATCH] Initialise multierror with env is not found Also wrap `os.Stat()` error when checking env value. --- gss/gokrb5.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gss/gokrb5.go b/gss/gokrb5.go index 4cdbb96..321504e 100644 --- a/gss/gokrb5.go +++ b/gss/gokrb5.go @@ -6,6 +6,7 @@ package gss import ( "encoding/hex" "errors" + "fmt" "math" "net" "os" @@ -350,21 +351,26 @@ func findFile(env string, try []string) (string, error) { path, ok := os.LookupEnv(env) if ok { if _, err := os.Stat(path); err != nil { - return "", err + return "", fmt.Errorf("%s: %w", env, err) } + return path, nil } - var errs error + errs := fmt.Errorf("%s: not found", env) + for _, t := range try { _, err := os.Stat(t) if err != nil { errs = multierror.Append(errs, err) + if os.IsNotExist(err) { continue } + return "", errs } + return t, nil }