Skip to content

fix(config): seed --catalog-name from default-catalog in config file#1319

Open
rasta-rocket wants to merge 1 commit into
apache:mainfrom
rasta-rocket:fix_catalog_name_cfg
Open

fix(config): seed --catalog-name from default-catalog in config file#1319
rasta-rocket wants to merge 1 commit into
apache:mainfrom
rasta-rocket:fix_catalog_name_cfg

Conversation

@rasta-rocket

Copy link
Copy Markdown

Problem

The CLI --catalog-name flag defaults to "default". When a config file used a different name under default-catalog, that value was never read ‚ ParseConfig was called with the flag's default before the config file had any chance to influence it. The result was a silent fallback to the rest catalog type with no URI, producing a confusing error:

Get "v1/config": unsupported protocol scheme ""

Example config that triggered the bug:

default-catalog: my-catalog
catalog:
  my-catalog:
    type: glue
    warehouse: s3://my-bucket

Running iceberg list would fail because my-catalog was never found in the catalog map, mergeConf was never called, and the catalog type stayed as rest.

Fix

  • Add config.ParseDefaultCatalog to extract default-catalog from the YAML without requiring a catalog name upfront.
  • In main, load the config bytes once, then seed args.CatalogName from default-catalog when --catalog-name was not explicitly passed on the command line. The explicit-flag guard ensures CLI flags still take precedence.

How to test

  1. Create ~/.iceberg-go.yaml with a non-"default" catalog name:
default-catalog: my-glue
catalog:
  my-glue:
    type: glue
    warehouse: s3://my-bucket
  1. Run without --catalog-name:
AWS_PROFILE=my-profile AWS_REGION=my-region iceberg list
  1. Before: Get "v1/config": unsupported protocol scheme ""
    After: connects to the Glue catalog correctly.

  2. Verify explicit flag still wins:

iceberg --catalog-name other-catalog list
  1. Should use other-catalog, not my-glue.

@rasta-rocket rasta-rocket requested a review from zeroshade as a code owner June 26, 2026 10:25
When a config file set `default-catalog` to a non-"default" name, the CLI
would silently ignore it because ParseConfig was called with the flag's
default value of "default" before the config was consulted. Add
ParseDefaultCatalog and apply it in main before the catalog lookup, so
the config file's default-catalog seeds args.CatalogName when the flag
is not explicitly passed on the command line.
@rasta-rocket rasta-rocket force-pushed the fix_catalog_name_cfg branch from d0f30d8 to f93dd0d Compare June 26, 2026 10:46

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Precedence is right: explicit --catalog-name wins, then the config file's default-catalog, then the built-in default; the nil-config and empty-default-catalog cases resolve correctly too. A couple of small nits inline, none blocking.

Comment thread config/config.go
return file
}

func ParseDefaultCatalog(file []byte) string {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this unmarshals the same bytes that ParseConfig re-unmarshals on the very next line - two parses of the same config per run. Harmless for a CLI, but you could return both the *CatalogConfig and the default-catalog name from a single parse and drop this helper. Also, since it's newly exported, a one-line doc comment would be good.

Comment thread cmd/iceberg/main.go

fileCfg := config.ParseConfig(config.LoadConfig(args.Config), args.CatalogName)
configData := config.LoadConfig(args.Config)
if !explicitFlags["catalog-name"] {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this seeding path (seed from default-catalog when the flag is absent, explicit flag wins) is exactly what the PR fixes, but it isn't covered by a test. A small args_test.go case asserting args.CatalogName is seeded when --catalog-name is omitted (and left alone when it's explicit) would guard against regressions.

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