diff --git a/amber/src/main/python/core/storage/iceberg/iceberg_document.py b/amber/src/main/python/core/storage/iceberg/iceberg_document.py index 997ab9b5b70..7a5beda916d 100644 --- a/amber/src/main/python/core/storage/iceberg/iceberg_document.py +++ b/amber/src/main/python/core/storage/iceberg/iceberg_document.py @@ -17,6 +17,7 @@ import pyarrow as pa from itertools import islice +from loguru import logger from pyiceberg.catalog import Catalog from pyiceberg.schema import Schema from pyiceberg.table import Table, FileScanTask @@ -211,9 +212,9 @@ def _seek_to_usable_file(self) -> Iterator[FileScanTask]: self.num_of_skipped_records += record_count continue yield task - except Exception: - print("Could not read iceberg table:\n") - raise Exception + except Exception as err: + logger.exception(err) + raise else: return iter([]) diff --git a/amber/src/test/python/core/storage/iceberg/test_iceberg_iterator_error_paths.py b/amber/src/test/python/core/storage/iceberg/test_iceberg_iterator_error_paths.py new file mode 100644 index 00000000000..d724ac31d53 --- /dev/null +++ b/amber/src/test/python/core/storage/iceberg/test_iceberg_iterator_error_paths.py @@ -0,0 +1,37 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from unittest.mock import Mock, patch + +import pytest + +from core.storage.iceberg import iceberg_document +from core.storage.iceberg.iceberg_document import IcebergIterator + + +def test_seek_to_usable_file_preserves_original_error(): + failing_table = Mock() + failing_table.refresh.side_effect = RuntimeError( + "Catalog auth failure: token expired" + ) + + with patch.object( + iceberg_document, "load_table_metadata", return_value=failing_table + ): + it = IcebergIterator(0, None, None, "ns", "tbl", None, None) + with pytest.raises(RuntimeError, match="Catalog auth failure"): + next(it)