Skip to content

fix: default value for GetCustom method#10

Merged
hgiasac merged 1 commit intomainfrom
fix/default-value
Mar 9, 2026
Merged

fix: default value for GetCustom method#10
hgiasac merged 1 commit intomainfrom
fix/default-value

Conversation

@hgiasac
Copy link
Copy Markdown
Collaborator

@hgiasac hgiasac commented Mar 9, 2026

This pull request updates environment variable retrieval logic across multiple types in the goenvconf package to handle missing required environment variable values more gracefully. Specifically, it changes error handling in all GetCustom methods so that only unexpected errors cause early returns, while the absence of a required value (ErrEnvironmentVariableValueRequired) is handled without failing immediately.

Improved error handling for environment variable retrieval:

  • All GetCustom methods for environment variable types (EnvAny, EnvString, EnvInt, EnvBool, EnvFloat) now only return errors if they are not ErrEnvironmentVariableValueRequired, allowing fallback logic to execute when a required value is missing. (any.go, environment.go) [1] [2] [3] [4] [5]
  • All GetCustom methods for map types (EnvMapString, EnvMapInt, EnvMapFloat, EnvMapBool) adopt the same error handling pattern, improving consistency and robustness. (map.go) [1] [2] [3] [4]
  • All GetCustom methods for slice types (EnvStringSlice, EnvIntSlice, EnvFloatSlice, EnvBoolSlice) also implement this improved error handling. (slice.go) [1] [2] [3] [4]

Dependency updates:

  • Added errors import in relevant files to support the new error handling logic. (any.go, map.go, slice.go) [1] [2] [3]

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the GetCustom methods across all environment variable types in the goenvconf package to handle ErrEnvironmentVariableValueRequired gracefully. Previously, when a custom GetEnvFunc returned this error (e.g., when an environment variable doesn't exist), GetCustom would immediately return the error instead of falling through to check the fallback Value field. This aligns GetCustom behavior with the existing GetOrDefault pattern.

Changes:

  • Updated all GetCustom methods to skip ErrEnvironmentVariableValueRequired errors, allowing fallback to the Value field when the environment variable is missing.
  • Added errors import to any.go, map.go, and slice.go to support the errors.Is() check.
  • Applied a slightly different but semantically equivalent pattern for EnvString.GetCustom (early return on success) compared to other types (check rawValue != "").

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
environment.go Updated GetCustom for EnvString, EnvInt, EnvBool, EnvFloat to handle ErrEnvironmentVariableValueRequired gracefully
any.go Updated EnvAny.GetCustom with same error handling pattern; added errors import
map.go Updated GetCustom for EnvMapString, EnvMapInt, EnvMapFloat, EnvMapBool; added errors import
slice.go Updated GetCustom for EnvStringSlice, EnvIntSlice, EnvFloatSlice, EnvBoolSlice; added errors import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread environment.go
@hgiasac hgiasac merged commit cf6df12 into main Mar 9, 2026
5 checks passed
@hgiasac hgiasac deleted the fix/default-value branch March 9, 2026 17:52
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.

2 participants