Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: inline Environment #403

Merged
merged 16 commits into from
Nov 26, 2020
Merged
Prev Previous commit
Next Next commit
fix: return env names with error
  • Loading branch information
Duologic committed Nov 20, 2020
commit 065a3e1c6606861f2e8bfc2e5a931cf75d796c1a
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this error message include the names of the environments? Makes it far easier to debug then

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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