Skip to content

Commit 2300d52

Browse files
bosdbosd
authored andcommitted
Fix: Narrow exception handling in sort_for_self_referencing function
- Replaced broad 'except Exception' with specific Polars exceptions - Now only catches pl.exceptions.ComputeError and pl.exceptions.ShapeError for schema/validation issues - FileNotFoundError and other system exceptions now properly propagate as fatal errors - This prevents masking important system errors like PermissionError while still handling CSV parsing/schema validation gracefully Addresses review comment about overly broad exception handling.
1 parent 3b77659 commit 2300d52

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/odoo_data_flow/lib/sort.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,13 @@ def sort_for_self_referencing(
5151
truncate_ragged_lines=True,
5252
infer_schema_length=0, # Don't infer schema, treat everything as string
5353
)
54-
except FileNotFoundError as e:
54+
except (FileNotFoundError, pl.exceptions.NoDataError) as e:
5555
_show_error_panel(
5656
"File Read Error", f"Could not read the file {file_path}: {e}"
5757
)
5858
return False # Return False to indicate an error occurred
59-
except pl.exceptions.NoDataError as e:
60-
_show_error_panel(
61-
"File Read Error", f"Could not read the file {file_path}: {e}"
62-
)
63-
return False # Return False to indicate an error occurred
64-
except Exception as e:
65-
# For other errors (like schema validation), we don't want to abort the import
59+
except (pl.exceptions.ComputeError, pl.exceptions.ShapeError) as e:
60+
# For schema/validation errors, we don't want to abort the import
6661
# These should be handled by the field validation preflight check
6762
log.warning(f"Could not fully parse file {file_path} for sorting: {e}")
6863
return None # Return None to indicate no sorting needed/possible

0 commit comments

Comments
 (0)