Conversation
There was a problem hiding this comment.
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
GetCustommethods to skipErrEnvironmentVariableValueRequirederrors, allowing fallback to theValuefield when the environment variable is missing. - Added
errorsimport toany.go,map.go, andslice.goto support theerrors.Is()check. - Applied a slightly different but semantically equivalent pattern for
EnvString.GetCustom(early return on success) compared to other types (checkrawValue != "").
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request updates environment variable retrieval logic across multiple types in the
goenvconfpackage to handle missing required environment variable values more gracefully. Specifically, it changes error handling in allGetCustommethods 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:
GetCustommethods for environment variable types (EnvAny,EnvString,EnvInt,EnvBool,EnvFloat) now only return errors if they are notErrEnvironmentVariableValueRequired, allowing fallback logic to execute when a required value is missing. (any.go,environment.go) [1] [2] [3] [4] [5]GetCustommethods for map types (EnvMapString,EnvMapInt,EnvMapFloat,EnvMapBool) adopt the same error handling pattern, improving consistency and robustness. (map.go) [1] [2] [3] [4]GetCustommethods for slice types (EnvStringSlice,EnvIntSlice,EnvFloatSlice,EnvBoolSlice) also implement this improved error handling. (slice.go) [1] [2] [3] [4]Dependency updates:
errorsimport in relevant files to support the new error handling logic. (any.go,map.go,slice.go) [1] [2] [3]