-
Notifications
You must be signed in to change notification settings - Fork 5.5k
refactor(native): Fail on empty or non-existent config environment variable #26741
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
base: master
Are you sure you want to change the base?
Conversation
Reviewer's GuideThis PR strengthens configuration handling by making the config reader fail fast when encountering empty or non-existent environment variables, and extends unit tests to verify both normal substitution behavior and the new error cases. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- The new error message for invalid environment variables conflates non-existent and empty cases; consider differentiating these in the message (or including the actual value for the empty case) to make debugging misconfigurations easier.
- In
readConfigEnvVarTest, thetestInvalidEnvVarhelper hardcodes the expected error strings; you could construct the expected message using the variable name to avoid duplication and keep the test resilient to future wording changes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new error message for invalid environment variables conflates non-existent and empty cases; consider differentiating these in the message (or including the actual value for the empty case) to make debugging misconfigurations easier.
- In `readConfigEnvVarTest`, the `testInvalidEnvVar` helper hardcodes the expected error strings; you could construct the expected message using the variable name to avoid duplication and keep the test resilient to future wording changes.
## Individual Comments
### Comment 1
<location> `presto-native-execution/presto_cpp/main/common/tests/ConfigTest.cpp:356-364` </location>
<code_context>
ASSERT_EQ(properties, expected);
+ // Empty env var
+ auto testInvalidEnvVar = [this](
+ const std::string& fileContent,
+ const std::string& expectedErrorMsg) {
+ cleanupConfigFilePath();
+ setUpConfigFilePath();
+ writeConfigFile(fileContent);
+ VELOX_ASSERT_THROW(
+ presto::util::readConfig(configFilePath_), expectedErrorMsg);
+ };
+
+ setenv(kEmptyEnvVarName.c_str(), "", 1);
</code_context>
<issue_to_address>
**suggestion (testing):** Consider making the invalid env-var assertions more explicit and slightly less brittle than matching the full error string.
`testInvalidEnvVar` currently uses `VELOX_ASSERT_THROW` with the full error message, which makes the test brittle to minor wording changes. If supported, it would be better to assert on a regex or substring that checks only the key parts (e.g., env var name and that it is missing/empty). If you intentionally want to lock down the exact user-facing text, please add a brief comment to document that choice for future maintainers.
Suggested implementation:
```cpp
std::unordered_map<std::string, std::string> expected{
{kEnvVarKey, kEnvVarValue},
{kEnvVarKey2, "${PRESTO_READ_CONFIG_TEST_VAR"},
{kEnvVarKey3, "PRESTO_READ_CONFIG_TEST_VAR}"},
{kNoEnvVarKey, "${}"}};
ASSERT_EQ(properties, expected);
// Empty env var: use a substring error match to keep the test robust
// against minor wording changes while still validating the key behavior.
auto testInvalidEnvVar =
[this](const std::string& fileContent,
const std::string& expectedErrorPattern) {
cleanupConfigFilePath();
setUpConfigFilePath();
writeConfigFile(fileContent);
VELOX_ASSERT_THROW(
presto::util::readConfig(configFilePath_), expectedErrorPattern);
};
// Set the env var to an empty string and verify that readConfig fails.
setenv(kEmptyEnvVarName.c_str(), "", 1);
testInvalidEnvVar(
kEnvVarKey + "=${" + kEmptyEnvVarName + "}",
// Only assert on the presence of the env-var name in the error message
// instead of the full user-facing string to avoid brittle tests.
kEmptyEnvVarName);
```
1. Ensure that `kEmptyEnvVarName` is defined in this test file (as it was in the developer's original change) and refers to the env-var key used in the config string.
2. If `setenv` is not already used elsewhere in this file, make sure `<cstdlib>` (or the appropriate header providing `setenv`) is included at the top of the file.
3. If more invalid-env-var cases are desired (e.g., unset variable, malformed `${}`), you can add more `testInvalidEnvVar` calls with different `fileContent` strings and stable `expectedErrorPattern` substrings.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
5802108 to
b8631ae
Compare
| } | ||
| value = std::string(envVal); | ||
|
|
||
| if (envVal == nullptr || strlen(envVal) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nmahadevuni : This does have the side effect that we were allowing empty values in the past, but will not going forth.
Can you give more information about the context in which you encountered the errors ? That would give us more understanding of how to change this logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only for configs that are set using the env vars. In recent internal issues, due to dynamic catalog loading, we have seen issues where env vars were not set correctly and logs didn't give any clue as to what went wrong. We want to catch such issues while loading catalog.
Description
This change is to report error when config properties reader finds an empty or non-existent envrionment variable.
Motivation and Context
If environment variable is empty or non-existent, we are quietly discarding it and loading the catalog which is causing issues while accessing the catalog assuming all is right with it.
Impact
No impact
Test Plan
Added test in ConfigTest.cpp