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

Treat deserialization errors from empty env vars as unset env var #39

Merged
merged 2 commits into from
Oct 18, 2024

Conversation

LukasKalbertodt
Copy link
Owner

@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?

@jdx
Copy link

jdx commented Oct 11, 2024

I think it's great!

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?
@LukasKalbertodt LukasKalbertodt force-pushed the empty-string-env-is-unset-sometimes branch from cd6b25f to 035fd45 Compare October 18, 2024 12:18
@LukasKalbertodt LukasKalbertodt merged commit ed402c4 into main Oct 18, 2024
2 checks passed
@LukasKalbertodt LukasKalbertodt deleted the empty-string-env-is-unset-sometimes branch October 18, 2024 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

empty strings for env bools
2 participants