-
Notifications
You must be signed in to change notification settings - Fork 214
fix(config): seed --catalog-name from default-catalog in config file #1319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -236,7 +236,14 @@ func main() { | |
| } | ||
| } | ||
|
|
||
| fileCfg := config.ParseConfig(config.LoadConfig(args.Config), args.CatalogName) | ||
| configData := config.LoadConfig(args.Config) | ||
| // Pass the catalog name only when it was set explicitly on the command line; otherwise | ||
| // pass "" so ParseConfig resolves it from the file's default-catalog. Explicit wins. | ||
| lookupName := "" | ||
| if explicitFlags["catalog-name"] { | ||
| lookupName = args.CatalogName | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One gap worth a thought: if A warning like |
||
| fileCfg := config.ParseConfig(configData, lookupName) | ||
| if fileCfg != nil { | ||
| mergeConf(fileCfg, &args, explicitFlags) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,12 +69,23 @@ func LoadConfig(configPath string) []byte { | |
| return file | ||
| } | ||
|
|
||
| // ParseConfig unmarshals the config file once and resolves the catalog to use. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a new exported function with no test, and I'd add a small table-driven |
||
| // When catalogName is empty, it falls back to the file's default-catalog field and | ||
| // then to the built-in "default" name. It returns the matching CatalogConfig, or | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This swallows the unmarshal error and returns So a YAML typo becomes indistinguishable from the original bug. I'd at minimum log the error here, or better return |
||
| // nil if no such catalog is defined in the file. | ||
| func ParseConfig(file []byte, catalogName string) *CatalogConfig { | ||
| var config Config | ||
| err := yaml.Unmarshal(file, &config) | ||
| if err != nil { | ||
| if err := yaml.Unmarshal(file, &config); err != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unmarshals the full I'd factor out a shared |
||
| return nil | ||
| } | ||
|
|
||
| if catalogName == "" { | ||
| catalogName = config.DefaultCatalog | ||
| } | ||
| if catalogName == "" { | ||
| catalogName = "default" | ||
| } | ||
|
|
||
| res, ok := config.Catalogs[catalogName] | ||
| if !ok { | ||
| return nil | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The precedence behavior here —
default-catalogseedsargs.CatalogNameonly when the flag wasn't passed, explicit flag wins — is the whole point of the fix, and it's untested.I'd pull the seeding into a testable helper, something like
resolveCatalogName(args Args, explicitFlags map[string]bool, configData []byte) string, and cover all three tiers: explicit flag, configdefault-catalog, and the bare"default"fallback. Otherwise an init-ordering or scanner refactor can quietly bring the bug back.