fix: handle missing config file without panicking#61
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a regression where LoadConfig errors when the default .pgmgr.json config file is missing, restoring support for env-var/flag-only configuration.
Changes:
- Extend the
argumentContextinterface withIsSet(string) booland use it inLoadConfig. - Update
populateFromFileto ignoreos.ErrNotExistonly when the config path was not explicitly provided. - Add tests covering missing default config behavior vs explicitly-provided missing paths (flag/env var).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pgmgr/config.go |
Passes IsSet("config-file") into populateFromFile to distinguish default vs explicit config paths and conditionally ignore missing default file errors. |
pgmgr/config_test.go |
Adds IsSet support to TestContext and introduces tests validating default-missing vs explicit-missing config file behavior. |
Comments suppressed due to low confidence (1)
pgmgr/config.go:93
json.Unmarshal(contents, &config)unmarshals into a**Config(pointer-to-pointer) becauseconfigis already a*Configreceiver. This will update only the local pointer variable and will not populate the caller’sConfiginstance, so config-file settings won’t actually be applied. Unmarshal into the receiver itself (passconfig, not&config).
return err
}
if err := json.Unmarshal(contents, &config); err != nil {
return err
💡 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.
Summary
LoadConfigwould fatal-error when.pgmgr.jsondoesn't exist, breaking users relying solely on env-var configurationpopulateFromFilenow silently ignoresos.ErrNotExistwhen the config file path was not explicitly set by the user (i.e. uses the CLI default.pgmgr.json)How It Works
argumentContextgains anIsSet(string) boolmethod (already implemented bycli.Context).LoadConfigpassesctx.IsSet("config-file")topopulateFromFile, which uses it to distinguish:--config-fileorPGMGR_CONFIG_FILEnot found => return error