| 1 |
// Copyright 2019 The Kubernetes Authors. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package types |
| 5 |
|
| 6 |
import ( |
| 7 |
"fmt" |
| 8 |
"strings" |
| 9 |
|
| 10 |
"sigs.k8s.io/kustomize/kyaml/errors" |
| 11 |
) |
| 12 |
|
| 13 |
type errUnableToFind struct { |
| 14 |
// What are we unable to find? |
| 15 |
what string |
| 16 |
// What things did we try? |
| 17 |
attempts []Pair |
| 18 |
} |
| 19 |
|
| 20 |
func (e *errUnableToFind) Error() string { |
| 21 |
var m []string |
| 22 |
for _, p := range e.attempts { |
| 23 |
m = append(m, "('"+p.Value+"'; "+p.Key+")") |
| 24 |
} |
| 25 |
return fmt.Sprintf( |
| 26 |
"unable to find %s - tried: %s", e.what, strings.Join(m, ", ")) |
| 27 |
} |
| 28 |
|
| 29 |
func NewErrUnableToFind(w string, a []Pair) *errUnableToFind { |
| 30 |
return &errUnableToFind{what: w, attempts: a} |
| 31 |
} |
| 32 |
|
| 33 |
func IsErrUnableToFind(err error) bool { |
| 34 |
e := &errUnableToFind{} |
| 35 |
return errors.As(err, &e) |
| 36 |
} |