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

Support querying environment variable presence/absence #454

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Gabriella439
Copy link
Owner

Fixes #452

Copy link

@9999years 9999years left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Two comments:

  1. The names don't include env or anything like it, which is a little ambiguous, especially because they take a Text. I could imagine reading isPresent "foo" and thinking it's testing if a file exists.
  2. I think isSet and isUnset are potential footguns — in my experience, it's very rare to consider a variable 'set' if it exists but is set to the empty string. We might consider adding a note to this effect to the documentation. ("In most cases, you want isPresent.)

@Gabriella439
Copy link
Owner Author

Gabriella439 commented Mar 4, 2024

I'm happy to add an "env" or something to the names to address (1) so I'll do that.

I'm a bit surprised about (2) because I had the opposite point of view (that isPresent / isAbsent were the footguns). The reason why is that treating an in-band value (the empty value) as a sentinel value that means unset is a common source of programming errors (not just in Bash, but in general). Like, in the case of a simple binary toggle this is less of a concern, but when the environment value stores an actual payload that the program will use then there is a greater risk that the payload can be meaningfully present, but empty.

@9999years
Copy link

Hmm, that's true. In my experience most environment variables are used for simple toggles. I would also expect the program to do some validation if the environment variable has semantics (e.g. check that a path exists if it's supposed to represent a path, etc.).

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.

Check if an environment variable is set
2 participants