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

Better error messages for missing config vars #135

Open
kernel-panic96 opened this issue Feb 16, 2024 · 0 comments
Open

Better error messages for missing config vars #135

kernel-panic96 opened this issue Feb 16, 2024 · 0 comments

Comments

@kernel-panic96
Copy link

kernel-panic96 commented Feb 16, 2024

Hello, it would be nice if the error for when there is a missing variable expansion states that it is missing instead of "empty default". Example below.

go version - 1.21.2

uber-go/config version - 1.4.0

sidecar:
  global-tags:
    - "pod=$MY_POD_NAME"
    - "namespace=$MY_NAMESPACE"

main: go

func main() {
	cfgProvider, err := config.NewYAML(config.Source(strings.NewReader("sidecar: { log-level: INFO, global-tags: [pod=$POD, namespace=$NAMESPACE]}")), config.Expand(os.LookupEnv))
	if err != nil {
		zap.L().Fatal("could not read yaml config", zap.Error(err))
	}
	var cfg AppConfig
	if err := cfgProvider.Get("sidecar").Populate(&cfg); err != nil {
		zap.L().Fatal("could not read app config", zap.Error(err))
	}
}

output:

go run main.go # no exported env vars
{"level":"fatal","message":"could not read yaml config","error":"couldn't expand environment: default is empty for \"POD\" (use \"\" for empty string)"}

It would be clearer if the error was - "missing expansion variable {VAR_NAME}" instead of "default is empty".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant