Skip to content

bug hotfix#186

Merged
ryansurf merged 1 commit intomainfrom
feat-vibecode
Mar 2, 2026
Merged

bug hotfix#186
ryansurf merged 1 commit intomainfrom
feat-vibecode

Conversation

@ryansurf
Copy link
Owner

@ryansurf ryansurf commented Mar 2, 2026

General:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code:

  1. Does your submission pass tests?
  2. Have you run the linter/formatter on your code locally before submission?
  3. Have you updated the documentation/README to reflect your changes, as applicable?
  4. Have you added an explanation of what your changes do?
  5. Have you written new tests for your changes, as applicable?

Summary by Sourcery

Bug Fixes:

  • Prevent the CLI from raising unhandled exceptions when saving a report to the database fails by logging a warning instead.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 2, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Wraps database report persistence in a try/except to prevent failures from crashing the CLI run, logging a warning instead when saving fails.

Sequence diagram for CLI run with resilient report persistence

sequenceDiagram
    actor User
    participant CLI
    participant DBHandler
    participant Logger

    User->>CLI: run(lat, long, args)
    CLI->>CLI: _save_report(ocean_data_dict)
    alt db_handler is configured
        CLI->>DBHandler: insert_report(ocean_data_dict)
        alt insert_report succeeds
            DBHandler-->>CLI: success
        else insert_report raises Exception
            DBHandler-->>CLI: Exception
            CLI->>Logger: warning(Failed to save report to database.)
        end
    else no db_handler
        CLI-->>CLI: skip persistence
    end
    CLI-->>User: render output and exit
Loading

Updated class diagram for CLI report persistence and error handling

classDiagram
    class CLI {
        +db_handler
        +run(lat, long, args)
        -_save_report(ocean_data_dict)
        -_render_output(ocean_data_dict, arguments)
    }

    class DBHandler {
        +insert_report(ocean_data_dict)
    }

    class Logger {
        +warning(message)
    }

    CLI --> DBHandler : uses
    CLI --> Logger : logs warnings
Loading

File-Level Changes

Change Details Files
Make database report saving non-fatal by catching any exception and logging a warning instead of propagating the error.
  • Guard the call to the database handler's insert_report method with a try/except block.
  • Catch broad exceptions during report persistence to avoid interrupting normal CLI execution.
  • Log a warning message when report saving fails, while leaving the rest of the run flow unchanged.
src/cli.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ryansurf ryansurf merged commit 8c29462 into main Mar 2, 2026
8 of 10 checks passed
@ryansurf ryansurf deleted the feat-vibecode branch March 2, 2026 04:27
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Catching a bare Exception makes it harder to distinguish expected DB issues from programming errors; consider catching a more specific database-related exception type instead.
  • When logging the failure to save the report, include the exception details (e.g., exc_info=True or the exception object) so that debugging DB issues is easier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Catching a bare `Exception` makes it harder to distinguish expected DB issues from programming errors; consider catching a more specific database-related exception type instead.
- When logging the failure to save the report, include the exception details (e.g., `exc_info=True` or the exception object) so that debugging DB issues is easier.

## Individual Comments

### Comment 1
<location path="src/cli.py" line_range="66-68" />
<code_context>
         """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:
+                logger.warning("Failed to save report to database.")

</code_context>
<issue_to_address>
**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:

```python
    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.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +66 to +68
try:
self.db_handler.insert_report(ocean_data_dict)
except Exception:
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant