Merged
Conversation
edolstra
reviewed
Dec 12, 2025
| * variable is set to "" | ||
| */ | ||
| std::optional<std::string> getEnvNonEmpty(const std::string & key); | ||
| std::optional<std::string> getEnvNonEmptyOptional(const std::string & key); |
Member
There was a problem hiding this comment.
Renaming this seems unnecessarily churny, plus the "optional" part is already part of the type signature so there's no need to put it in the name.
Member
Author
There was a problem hiding this comment.
The problem is that it looks deceptively simple, and you can't easily tell at a call site. Certainly not when reviewing.
Member
There was a problem hiding this comment.
Is using .value() not enough of an indication?
d3de95d to
db78bf1
Compare
Member
|
Dropped 92767ee for now, so we can already merge the other commits. |
The previous implementation called .value() on std::optional without checking if it had a value. When _NIX_TEST_UNIT_DATA was not set, this would throw std::bad_optional_access or cause a segfault in code that used the raw getenv() result. The new implementation checks the optional first and throws an Error with a helpful message directing users to run tests via meson. The example includes --gdb since this situation may arise when trying to debug tests without knowing about meson's test infrastructure.
The nix_api_store.cc tests and derivation-parser-bench.cc were using raw getenv() calls or unsafe .value() calls on optional, which would segfault when passed to std::filesystem::path constructor if the _NIX_TEST_UNIT_DATA environment variable was not set.
This is mostly theoretical, but the code was calling getenv("TZ")
twice: once to check if it's non-null, and again to get its value.
This creates a potential race condition where the environment could
change between calls.
db78bf1 to
76c09bf
Compare
xokdvium
approved these changes
Dec 13, 2025
Contributor
xokdvium
left a comment
There was a problem hiding this comment.
Mostly cosmetic, but overall lgtm and improves DX
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
See commit messages.
Context
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.