Treat deserialization errors from empty env vars as unset env var #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@jdx what do you think about this potential solution to your issue?
Fixes #35
I'm a bit worried that this might seem too much like magic, but I think this is just the most useful behavior in all situations I can think of. This covers not only Booleans, but also numbers and anything else for which an empty string is not a valid value. It also leaves types with empty strings as valid values untouched.
I've been thinking about how this behavior could confuse users. And I could only think of two cases:
A config value has a default value, and the user thinks that empty string is a valid value, when in fact it isn't. Then, setting
FOO=
will result in the default value, when the user expected an empty string. Here, a clear error "empty string invalid" would be more helpful.A config value with a type that can be deserialized from empty string, but the user thinks it cannot. Maybe the config value is a list of numbers, where "" is just an empty list, but the user thought it was a single number. Then setting
FOO=
means setting the value to an empty list.Not sure if any of these cases will happen often enough or is important enough to not merge this?