Skip to content

Commit

Permalink
Better error handling
Browse files Browse the repository at this point in the history
Show more common file content problems: Key and Value error
For all other error, report parsing error
  • Loading branch information
saravanabalagi committed Jul 20, 2023
1 parent c3961ea commit 4f0907c
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging

from odoo import fields, models
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -32,9 +33,15 @@ def _parse_file(self, data_file):
return Parser.parse(
data_file, self.sheet_mapping_id, self.statement_filename
)
except BaseException:
except KeyError as e:
e_str = f"Could not find value for {e.args[0]!r}"
raise UserError(f"Failed to parse uploaded file!\n{e_str}")

Check warning on line 38 in account_statement_import_txt_xlsx/models/account_statement_import.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_txt_xlsx/models/account_statement_import.py#L37-L38

Added lines #L37 - L38 were not covered by tests
except ValueError as e:
e_str = f"Problem with a value in file\n{e}"
raise UserError(f"Failed to parse uploaded file!\n{e_str}")
except BaseException as e:

Check warning on line 42 in account_statement_import_txt_xlsx/models/account_statement_import.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_txt_xlsx/models/account_statement_import.py#L40-L42

Added lines #L40 - L42 were not covered by tests
if self.env.context.get("account_statement_import_txt_xlsx_test"):
raise
raise UserError("Failed to parse uploaded file!")

Check warning on line 44 in account_statement_import_txt_xlsx/models/account_statement_import.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_txt_xlsx/models/account_statement_import.py#L44

Added line #L44 was not covered by tests
_logger.warning("Sheet parser error", exc_info=True)
return super()._parse_file(data_file)

Expand Down

0 comments on commit 4f0907c

Please sign in to comment.