Skip to content

Better error messages for missing config vars #135

@kernel-panic96

Description

@kernel-panic96

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions