Skip to content

Commit

Permalink
Log exception when FileIO import fails (#1578)
Browse files Browse the repository at this point in the history
Closes #1577.

Log the underlying exception when a FileIO import fails.
  • Loading branch information
rshkv authored Jan 26, 2025
1 parent 7be5cf2 commit 6fffb64
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pyiceberg/catalog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ def _import_catalog(name: str, catalog_impl: str, properties: Properties) -> Opt
module = importlib.import_module(module_name)
class_ = getattr(module, class_name)
return class_(name, **properties)
except ModuleNotFoundError:
logger.warning("Could not initialize Catalog: %s", catalog_impl)
except ModuleNotFoundError as exc:
logger.warning(f"Could not initialize Catalog: {catalog_impl}", exc_info=exc)
return None


Expand Down
4 changes: 2 additions & 2 deletions pyiceberg/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ def _import_file_io(io_impl: str, properties: Properties) -> Optional[FileIO]:
module = importlib.import_module(module_name)
class_ = getattr(module, class_name)
return class_(properties)
except ModuleNotFoundError:
logger.warning("Could not initialize FileIO: %s", io_impl)
except ModuleNotFoundError as exc:
logger.warning(f"Could not initialize FileIO: {io_impl}", exc_info=exc)
return None


Expand Down
4 changes: 2 additions & 2 deletions pyiceberg/table/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def _import_location_provider(
module = importlib.import_module(module_name)
class_ = getattr(module, class_name)
return class_(table_location, table_properties)
except ModuleNotFoundError:
logger.warning("Could not initialize LocationProvider: %s", location_provider_impl)
except ModuleNotFoundError as exc:
logger.warning(f"Could not initialize LocationProvider: {location_provider_impl}", exc_info=exc)
return None


Expand Down
4 changes: 3 additions & 1 deletion tests/io/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import os
import pickle
import tempfile
from typing import Any

import pytest

Expand Down Expand Up @@ -277,8 +278,9 @@ def test_import_file_io() -> None:
assert isinstance(_import_file_io(ARROW_FILE_IO, {}), PyArrowFileIO)


def test_import_file_io_does_not_exist() -> None:
def test_import_file_io_does_not_exist(caplog: Any) -> None:
assert _import_file_io("pyiceberg.does.not.exist.FileIO", {}) is None
assert "ModuleNotFoundError: No module named 'pyiceberg.does'" in caplog.text


def test_load_file() -> None:
Expand Down
5 changes: 3 additions & 2 deletions tests/table/test_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from typing import Optional
from typing import Any, Optional

import pytest

Expand Down Expand Up @@ -64,11 +64,12 @@ def test_custom_location_provider_single_path() -> None:
load_location_provider(table_location="table_location", table_properties={"write.py-location-provider.impl": "not_found"})


def test_custom_location_provider_not_found() -> None:
def test_custom_location_provider_not_found(caplog: Any) -> None:
with pytest.raises(ValueError, match=r"Could not initialize LocationProvider"):
load_location_provider(
table_location="table_location", table_properties={"write.py-location-provider.impl": "module.not_found"}
)
assert "ModuleNotFoundError: No module named 'module'" in caplog.text


def test_object_storage_no_partition() -> None:
Expand Down

0 comments on commit 6fffb64

Please sign in to comment.