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

print the name of the env var when a required var is missing #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions cleanenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,18 @@ func readEnvVars(cfg interface{}, update bool) error {
}

if rawValue == nil && meta.required && meta.isFieldValueZero() {
if len(meta.envList) == 0 {
return fmt.Errorf("env list for field %q is empty but is set as required", meta.fieldName)
}
if len(meta.envList) == 1 {
return fmt.Errorf(
"environment variable %q is required but the value is not provided",
meta.envList[0],
)
}
return fmt.Errorf(
"field %q is required but the value is not provided",
meta.fieldName,
"environment variable %q (aliases=%v) is required but the value is not provided",
meta.envList[0], meta.envList[1:],
)
}

Expand Down