-
Notifications
You must be signed in to change notification settings - Fork 160
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
Update aws_get_environment_value to return NULL for empty values #1141
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1141 +/- ##
==========================================
+ Coverage 83.82% 83.84% +0.01%
==========================================
Files 57 57
Lines 5991 5998 +7
==========================================
+ Hits 5022 5029 +7
Misses 969 969 ☔ View full report in Codecov by Sentry. |
This is a pretty big assumption since you're not only asserting it for right now, but for everything that comes in the future too. I don't really agree with this. |
source/posix/environment.c
Outdated
@@ -14,7 +14,7 @@ int aws_get_environment_value( | |||
struct aws_string **value_out) { | |||
|
|||
const char *value = getenv(aws_string_c_str(variable_name)); | |||
if (value == NULL) { | |||
if (value == NULL || value[0] == '\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.
It sucks, but this is how it is with environment variables. Sometimes just the existence of the env-var is meaningful, even if it's blank. Maybe create an alternate function like aws_get_environment_variable_nonempty()
that has this behavior, and scrub the codebase for places that would benefit from using that instead
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.
Yeah, I agree. We can discuss the following options in the office tomorrow.
-
Modify the existing function, and we can create a new function in the future if required, like if we have a use case where
env-var
can be blank. -
Create a new function,
aws_get_environment_variable_nonempty
,aws_get_environment_variable_cursor
, oraws_get_environment_variable_c_str
. I prefer theaws_get_environment_variable_cursor
if we decide to just create a new function. -
Keep the function as it is, and validate all the uses to handle it correctly.
Description of changes:
aws_get_environment_value
is error-prone because one of the frequent use cases is to check an environment variable, else check other source like config file. In that case, the previous implementation required us to check three cases:Since we don't need to differentiate between empty values and unset values, treat empty environment values as unset.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.