Skip to content

Commit 6fffb64

Browse files
authored
Log exception when FileIO import fails (#1578)
Closes #1577. Log the underlying exception when a FileIO import fails.
1 parent 7be5cf2 commit 6fffb64

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

pyiceberg/catalog/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ def _import_catalog(name: str, catalog_impl: str, properties: Properties) -> Opt
298298
module = importlib.import_module(module_name)
299299
class_ = getattr(module, class_name)
300300
return class_(name, **properties)
301-
except ModuleNotFoundError:
302-
logger.warning("Could not initialize Catalog: %s", catalog_impl)
301+
except ModuleNotFoundError as exc:
302+
logger.warning(f"Could not initialize Catalog: {catalog_impl}", exc_info=exc)
303303
return None
304304

305305

pyiceberg/io/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ def _import_file_io(io_impl: str, properties: Properties) -> Optional[FileIO]:
315315
module = importlib.import_module(module_name)
316316
class_ = getattr(module, class_name)
317317
return class_(properties)
318-
except ModuleNotFoundError:
319-
logger.warning("Could not initialize FileIO: %s", io_impl)
318+
except ModuleNotFoundError as exc:
319+
logger.warning(f"Could not initialize FileIO: {io_impl}", exc_info=exc)
320320
return None
321321

322322

pyiceberg/table/locations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ def _import_location_provider(
129129
module = importlib.import_module(module_name)
130130
class_ = getattr(module, class_name)
131131
return class_(table_location, table_properties)
132-
except ModuleNotFoundError:
133-
logger.warning("Could not initialize LocationProvider: %s", location_provider_impl)
132+
except ModuleNotFoundError as exc:
133+
logger.warning(f"Could not initialize LocationProvider: {location_provider_impl}", exc_info=exc)
134134
return None
135135

136136

tests/io/test_io.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import os
1919
import pickle
2020
import tempfile
21+
from typing import Any
2122

2223
import pytest
2324

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

279280

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

283285

284286
def test_load_file() -> None:

tests/table/test_locations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
from typing import Optional
17+
from typing import Any, Optional
1818

1919
import pytest
2020

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

6666

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

7374

7475
def test_object_storage_no_partition() -> None:

0 commit comments

Comments
 (0)