Skip to content

Commit 065a3e1

Browse files
committed
fix: return env names with error
1 parent b6ae81b commit 065a3e1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

pkg/tanka/errors.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package tanka
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"strings"
6+
)
47

58
// ErrNoEnv means that the given jsonnet has no Environment object
69
// This must not be fatal, some operations work without
@@ -14,9 +17,10 @@ func (e ErrNoEnv) Error() string {
1417

1518
// ErrMultipleEnvs means that the given jsonnet has multiple Environment objects
1619
type ErrMultipleEnvs struct {
17-
path string
20+
path string
21+
names []string
1822
}
1923

2024
func (e ErrMultipleEnvs) Error() string {
21-
return fmt.Sprintf("found multiple Environments in '%s'", e.path)
25+
return fmt.Sprintf("found multiple Environments (%s) in '%s'", strings.Join(e.names, ", "), e.path)
2226
}

pkg/tanka/parse.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ func parseEnv(path string, opts jsonnet.Opts, evalFn evaluateFunc) (interface{},
198198
var env *v1alpha1.Environment
199199

200200
if len(extractedEnvs) > 1 {
201-
return data, nil, ErrMultipleEnvs{path}
201+
names := make([]string, 0)
202+
for _, exEnv := range extractedEnvs {
203+
names = append(names, exEnv.Metadata().Name())
204+
}
205+
return data, nil, ErrMultipleEnvs{path, names}
202206
} else if len(extractedEnvs) == 1 {
203207
marshalled, err := json.Marshal(extractedEnvs[0])
204208
if err != nil {

0 commit comments

Comments
 (0)