Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def run(self, lat=None, long=None, args=None):
def _save_report(self, ocean_data_dict):
"""Persists the report to the database if a handler is available."""
if self.db_handler:
self.db_handler.insert_report(ocean_data_dict)
try:
self.db_handler.insert_report(ocean_data_dict)
except Exception:
Comment on lines +66 to +68
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Catching bare Exception and only logging a generic warning may hide real errors and lose debugging context.

The try/except around the insert is reasonable, but catching Exception and logging only a generic warning can hide real issues. Consider catching the specific DB exception type (e.g. DatabaseError), logging the exception details (e.g. with exc_info=True), and re-raising unexpected exceptions so they don’t get silently ignored.

Suggested implementation:

    def _save_report(self, ocean_data_dict):
        """Persists the report to the database if a handler is available."""
        if self.db_handler:
            try:
                self.db_handler.insert_report(ocean_data_dict)
            except DatabaseError:
                logger.warning("Failed to save report to database.", exc_info=True)
            except Exception:
                # Re-raise unexpected exceptions so they are not silently ignored
                logger.exception("Unexpected error while saving report to database.")
                raise
  1. Import or define the appropriate DatabaseError type used by your DB layer. For example:
    • If using Python’s DB-API 2.0 directly: from sqlite3 import DatabaseError or from your chosen driver (e.g. psycopg2, mysql.connector, etc.).
    • If using SQLAlchemy: from sqlalchemy.exc import SQLAlchemyError as DatabaseError.
  2. Ensure logger is defined/imported in src/cli.py (e.g. import logging and logger = logging.getLogger(__name__)) if not already present.
  3. Optionally, narrow DatabaseError further if your DB library exposes more specific exception subclasses (e.g. IntegrityError, OperationalError) and you want tailored handling.

logger.warning("Failed to save report to database.")

def _render_output(self, ocean_data_dict, arguments):
"""Renders JSON or human-readable output based on arguments."""
Expand Down
Loading