Skip to content

Commit

Permalink
Initialise multierror with env is not found
Browse files Browse the repository at this point in the history
Also wrap `os.Stat()` error when checking env value.
  • Loading branch information
bodgit committed Feb 11, 2023
1 parent a2d9455 commit 45db94c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gss/gokrb5.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package gss
import (
"encoding/hex"
"errors"
"fmt"
"math"
"net"
"os"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 45db94c

Please sign in to comment.