feat: make environment loading transactional - #4
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Why
Environment variables are process-global state. A failed load must not leave a new endpoint paired with an old credential or destroy the last working configuration.
Previously, files were applied one at a time. A later parse or write failure could happen after earlier values had already changed, and reload began by unsetting previously loaded keys. This pass makes loading transactional and deterministic.
What
Load,Reload, andIsEnvLoadedstate.APP_ENVselect the application layer in the same load.MustGetInt,MustGetBool, native-widthGetUint, map trimming, and enum fallback behavior.Dumpdoes not redact secrets.Before / after
MustGet*0orfalseReload now behaves like ownership transfer:
Compatibility
This is not a breaking API release: public function signatures remain unchanged.
Loading and reloading now publish all selected files atomically because preserving partial application would leave mixed credentials and endpoints.
APP_ENVdeclared in the base file now selects its application layer during that same load, so deployments that previously selected a layer only through the ambient environment should review precedence. InvalidMustGetIntandMustGetBoolvalues now panic because theMustcontract represents a required valid value, while map trimming and enum fallback changes correct parsing inconsistencies.Applications that depended on partial loads, destructive reload unsets, or invalid required values should update, but those paths were failures of the existing contract rather than supported extension points.
Notes
Public function signatures remain unchanged, and
LoadEnvFileIfExistsremains an alias forLoad.Behavior to account for:
Review
loader.gocontains planning, application, rollback, and ownership tracking.loader_test.gocovers empty/unset restoration, failed writes, reloads, discovery, and concurrency.env.go,container.go,host.go, andscope.gocontain the getter and runtime corrections.