Skip to content

Commit 09de790

Browse files
authored
fix: show helpful error when hive catalog config is missing uri (#3077)
Closes #3069 # Rationale for this change When a catalog is explicitly configured with `type: hive` but `uri` is missing in `.pyiceberg.yaml`, the CLI currently fails with a raw `KeyError('uri')`, which is surfaced as just: `'uri'` ```bash ❯ cat .pyiceberg.yaml catalog: my_hive_catalog: type: hive warehouse: warehouse_loc ❯ uv run pyiceberg --catalog my_hive_catalog list 'uri' ``` It's confusing for users because the command appears to return an identifier-like value instead of a configuration error. This change adds explicit validation for required catalog properties when the catalog type is already specified (e.g. `hive`, `rest`, `sql`), so users get a clear actionable error message instead. ## Are these changes tested? Yes. - Added a CLI regression test for `--catalog <name> list` with `type: hive` and missing `uri` - Verified the error output contains a helpful `URI missing...` message and no longer prints `'uri'` ## Are there any user-facing changes? Yes. Users now see a clear error message (for example): `URI missing, please provide using --uri, the config or environment variable PYICEBERG_CATALOG__<CATALOG_NAME>__URI` instead of a raw `'uri'` error when `type: hive` is configured without `uri`.
1 parent 15577e7 commit 09de790

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pyiceberg/catalog/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ def infer_catalog_type(name: str, catalog_properties: RecursiveDict) -> CatalogT
218218
)
219219

220220

221+
def _check_required_catalog_properties(name: str, catalog_type: CatalogType, conf: RecursiveDict) -> None:
222+
"""Validate required properties for explicitly selected catalog types."""
223+
if catalog_type in {CatalogType.REST, CatalogType.HIVE, CatalogType.SQL} and URI not in conf:
224+
raise ValueError(
225+
f"URI missing, please provide using --uri, the config or environment variable PYICEBERG_CATALOG__{name.upper()}__URI"
226+
)
227+
228+
221229
def load_catalog(name: str | None = None, **properties: str | None) -> Catalog:
222230
"""Load the catalog based on the properties.
223231
@@ -263,6 +271,7 @@ def load_catalog(name: str | None = None, **properties: str | None) -> Catalog:
263271
catalog_type = infer_catalog_type(name, conf)
264272

265273
if catalog_type:
274+
_check_required_catalog_properties(name, catalog_type, conf)
266275
return AVAILABLE_CATALOGS[catalog_type](name, cast(dict[str, str], conf))
267276

268277
raise ValueError(f"Could not initialize catalog with the following properties: {properties}")

tests/cli/test_console.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ def test_missing_uri(mocker: MockFixture, empty_home_dir_path: str) -> None:
4848
assert result.output == "Could not initialize catalog with the following properties: {}\n"
4949

5050

51+
def test_hive_catalog_missing_uri_shows_helpful_error(mocker: MockFixture) -> None:
52+
mock_env_config = mocker.MagicMock()
53+
mock_env_config.get_catalog_config.return_value = {"type": "hive"}
54+
mocker.patch("pyiceberg.catalog._ENV_CONFIG", mock_env_config)
55+
56+
runner = CliRunner()
57+
result = runner.invoke(run, ["--catalog", "my_hive_catalog", "list"])
58+
59+
assert result.exit_code == 1
60+
assert "URI missing, please provide using --uri" in result.output
61+
assert "'uri'" not in result.output
62+
63+
5164
@pytest.fixture(autouse=True)
5265
def env_vars(mocker: MockFixture) -> None:
5366
mocker.patch.dict(os.environ, MOCK_ENVIRONMENT)

0 commit comments

Comments
 (0)