Skip to content

feat(flagd): log error on invalid env var parsing#1773

Draft
buildingisfun23 wants to merge 1 commit intoopen-feature:mainfrom
buildingisfun23:feat/1673-log-invalid-env-vars
Draft

feat(flagd): log error on invalid env var parsing#1773
buildingisfun23 wants to merge 1 commit intoopen-feature:mainfrom
buildingisfun23:feat/1673-log-invalid-env-vars

Conversation

@buildingisfun23
Copy link
Copy Markdown

Summary

  • Adds ERROR-level log output when environment variables cannot be parsed, instead of silently falling back to defaults
  • Covers integer, long, and list parsing in Config.java
  • Uses the existing @Slf4j logger already present on the class

Fixes #1673

When flagd options in environment variables cannot be parsed (e.g.,
non-numeric value for an integer option), the code silently falls back
to default values. This adds ERROR-level log messages at each fallback
point so users are informed about misconfigurations.

Closes open-feature#1673
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces error logging to the environment variable fallback methods in the Config class to improve observability when parsing fails. The review feedback suggests including the caught exception in the log.error calls to capture stack traces for better debugging and recommends caching the environment variable value to avoid redundant System.getenv calls.

Comment on lines +88 to +92
log.error(
"Failed to parse env variable '{}' with value '{}' as int, using default: {}",
key,
System.getenv(key),
defaultValue);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

It is recommended to include the exception e in the log.error call. This allows the logger to capture the stack trace and the specific error message (e.g., why the integer parsing failed), which is invaluable for debugging. Additionally, note that System.getenv(key) is called multiple times in this method; while not a performance bottleneck in a configuration loader, it is generally better practice to retrieve the value once to ensure consistency and avoid redundant system lookups.

Suggested change
log.error(
"Failed to parse env variable '{}' with value '{}' as int, using default: {}",
key,
System.getenv(key),
defaultValue);
log.error(
"Failed to parse env variable '{}' with value '{}' as int, using default: {}",
key,
System.getenv(key),
defaultValue,
e);

Comment on lines +101 to +105
log.error(
"Failed to parse env variable '{}' with value '{}' as long, using default: {}",
key,
System.getenv(key),
defaultValue);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Including the exception e in the log output provides the root cause of the parsing failure, which aids in troubleshooting. Also, consider capturing the result of System.getenv(key) in a variable at the start of the method to avoid redundant calls and potential (though unlikely) consistency issues if the environment were to change between calls.

Suggested change
log.error(
"Failed to parse env variable '{}' with value '{}' as long, using default: {}",
key,
System.getenv(key),
defaultValue);
log.error(
"Failed to parse env variable '{}' with value '{}' as long, using default: {}",
key,
System.getenv(key),
defaultValue,
e);

Comment on lines +118 to +122
log.error(
"Failed to parse env variable '{}' with value '{}' as list, using default: {}",
key,
System.getenv(key),
defaultValue);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Adding the exception e to the log call ensures that any unexpected errors during the stream processing or splitting are properly documented with a stack trace. As with the other fallback methods, retrieving the environment variable once and reusing it would be more efficient and robust than multiple System.getenv(key) calls.

Suggested change
log.error(
"Failed to parse env variable '{}' with value '{}' as list, using default: {}",
key,
System.getenv(key),
defaultValue);
log.error(
"Failed to parse env variable '{}' with value '{}' as list, using default: {}",
key,
System.getenv(key),
defaultValue,
e);

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.

[flagd] Add log output on invalid env vars

5 participants