Skip to content

Commit

Permalink
fix: return env names with error
Browse files Browse the repository at this point in the history
  • Loading branch information
Duologic committed Nov 20, 2020
1 parent b6ae81b commit 065a3e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pkg/tanka/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package tanka

import "fmt"
import (
"fmt"
"strings"
)

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

// ErrMultipleEnvs means that the given jsonnet has multiple Environment objects
type ErrMultipleEnvs struct {
path string
path string
names []string
}

func (e ErrMultipleEnvs) Error() string {
return fmt.Sprintf("found multiple Environments in '%s'", e.path)
return fmt.Sprintf("found multiple Environments (%s) in '%s'", strings.Join(e.names, ", "), e.path)
}
6 changes: 5 additions & 1 deletion pkg/tanka/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ func parseEnv(path string, opts jsonnet.Opts, evalFn evaluateFunc) (interface{},
var env *v1alpha1.Environment

if len(extractedEnvs) > 1 {
return data, nil, ErrMultipleEnvs{path}
names := make([]string, 0)
for _, exEnv := range extractedEnvs {
names = append(names, exEnv.Metadata().Name())
}
return data, nil, ErrMultipleEnvs{path, names}
} else if len(extractedEnvs) == 1 {
marshalled, err := json.Marshal(extractedEnvs[0])
if err != nil {
Expand Down

0 comments on commit 065a3e1

Please sign in to comment.