Skip to content

Commit adfe576

Browse files
refactor: Improve exception handling in Excel parser
- Change BaseException to Exception in both except blocks - Remove manual KeyboardInterrupt/SystemExit re-raise (now propagates naturally) - Add explanatory comment for empty except block when seeking file pointer Addresses code quality bot feedback on PR #850 Co-Authored-By: unknown <>
1 parent 34fe892 commit adfe576

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

airbyte_cdk/sources/file_based/file_types/excel_parser.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,11 @@ def open_and_parse_file(
200200
file_url = getattr(file_info, "url", None)
201201
elif isinstance(file_info, str):
202202
file_label = file_info
203-
calamine_exc: Optional[BaseException] = None
203+
calamine_exc: Optional[Exception] = None
204204
try:
205205
with pd.ExcelFile(fp, engine="calamine") as excel_file: # type: ignore [arg-type, call-overload]
206206
return excel_file.parse() # type: ignore [no-any-return]
207-
except BaseException as exc: # noqa: BLE001
208-
if isinstance(exc, (KeyboardInterrupt, SystemExit)):
209-
raise
207+
except Exception as exc:
210208
calamine_exc = exc
211209
if logger:
212210
logger.warning(
@@ -220,6 +218,7 @@ def open_and_parse_file(
220218
try:
221219
fp.seek(0) # type: ignore [union-attr]
222220
except (AttributeError, OSError):
221+
# Some file-like objects may not be seekable; attempt openpyxl parsing anyway
223222
pass
224223

225224
try:
@@ -236,9 +235,7 @@ def open_and_parse_file(
236235
)
237236
)
238237
return df
239-
except BaseException as openpyxl_exc: # noqa: BLE001
240-
if isinstance(openpyxl_exc, (KeyboardInterrupt, SystemExit)):
241-
raise
238+
except Exception as openpyxl_exc:
242239
# If both engines fail, raise the original calamine exception
243240
if logger:
244241
logger.error(

0 commit comments

Comments
 (0)