Skip to content

fix: handle missing config file without panicking#61

Merged
rnubel merged 1 commit into
masterfrom
fix/missing-config-file
Apr 1, 2026
Merged

fix: handle missing config file without panicking#61
rnubel merged 1 commit into
masterfrom
fix/missing-config-file

Conversation

@rnubel
Copy link
Copy Markdown
Owner

@rnubel rnubel commented Apr 1, 2026

Summary

  • Fixes a regression from 16bf1ea where LoadConfig would fatal-error when .pgmgr.json doesn't exist, breaking users relying solely on env-var configuration
  • populateFromFile now silently ignores os.ErrNotExist when the config file path was not explicitly set by the user (i.e. uses the CLI default .pgmgr.json)
  • All other errors (malformed JSON, permission denied, explicitly-provided missing paths) remain fatal

How It Works

argumentContext gains an IsSet(string) bool method (already implemented by cli.Context). LoadConfig passes ctx.IsSet("config-file") to populateFromFile, which uses it to distinguish:

  • Default path not found => silently skip (env vars / CLI flags take over)
  • Explicit --config-file or PGMGR_CONFIG_FILE not found => return error

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

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 argumentContext interface with IsSet(string) bool and use it in LoadConfig.
  • Update populateFromFile to ignore os.ErrNotExist only 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) because config is already a *Config receiver. This will update only the local pointer variable and will not populate the caller’s Config instance, so config-file settings won’t actually be applied. Unmarshal into the receiver itself (pass config, 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.

@rnubel rnubel merged commit 0475d5c into master Apr 1, 2026
10 checks passed
@rnubel rnubel deleted the fix/missing-config-file branch April 1, 2026 16:22
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