Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ static int fallBackToEnvOrDefault(String key, int defaultValue) {
try {
return System.getenv(key) != null ? Integer.parseInt(System.getenv(key)) : defaultValue;
} catch (Exception e) {
log.error(
"Failed to parse env variable '{}' with value '{}' as int, using default: {}",
key,
System.getenv(key),
defaultValue);
Comment on lines +88 to +92
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);

return defaultValue;
}
}
Expand All @@ -93,6 +98,11 @@ static long fallBackToEnvOrDefault(String key, long defaultValue) {
try {
return System.getenv(key) != null ? Long.parseLong(System.getenv(key)) : defaultValue;
} catch (Exception e) {
log.error(
"Failed to parse env variable '{}' with value '{}' as long, using default: {}",
key,
System.getenv(key),
defaultValue);
Comment on lines +101 to +105
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);

return defaultValue;
}
}
Expand All @@ -105,6 +115,11 @@ static List<String> fallBackToEnvOrDefaultList(String key, List<String> defaultV
.collect(Collectors.toList())
: defaultValue;
} catch (Exception e) {
log.error(
"Failed to parse env variable '{}' with value '{}' as list, using default: {}",
key,
System.getenv(key),
defaultValue);
Comment on lines +118 to +122
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);

return defaultValue;
}
}
Expand Down
Loading