Skip to content

fix: replace bare except with except Exception#172

Open
harshadkhetpal wants to merge 3 commits into
Arvo-AI:mainfrom
harshadkhetpal:fix/bare-except-exception
Open

fix: replace bare except with except Exception#172
harshadkhetpal wants to merge 3 commits into
Arvo-AI:mainfrom
harshadkhetpal:fix/bare-except-exception

Conversation

@harshadkhetpal
Copy link
Copy Markdown
Contributor

@harshadkhetpal harshadkhetpal commented Mar 25, 2026

Summary

Replace bare except: clauses with except Exception: across 3 files (5 occurrences).

Bare except: catches all exceptions including SystemExit, KeyboardInterrupt, and GeneratorExit, which should typically propagate. Per PEP 8 (E722).

Files changed:

  • server/utils/db/db_adapters.py (2 occurrences)
  • server/utils/db/connection_pool.py (1 occurrence)
  • server/main_chatbot.py (2 occurrences)
# Before
except:

# After
except Exception:

Testing

No behavior change — style/correctness fix only.

Summary by CodeRabbit

  • Bug Fixes
    • Improved exception handling specificity in database connection and chatbot tool processing to prevent unintended error suppression during edge cases.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 25, 2026

📝 Walkthrough

Walkthrough

This pull request refines exception handling specificity across three modules. Tool argument parsing in the chatbot now catches only Exception instead of bare excepts, while database rollback handlers broaden from bare excepts to BaseException. No functional behavior changes—only the types of exceptions caught are modified.

Changes

Cohort / File(s) Summary
Chatbot Tool Argument Parsing
server/main_chatbot.py
Updated two tool input parsing blocks to catch Exception instead of bare except, preventing non-Exception base errors from being implicitly caught during message and value event tool calls.
Database Connection Error Handling
server/utils/db/connection_pool.py, server/utils/db/db_adapters.py
Broadened rollback exception handlers from bare except: to except BaseException: in three locations (one in connection pool, two in legacy context managers), expanding the range of exception types swallowed during rollback.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: replace bare except with except Exception' accurately describes the main change across all three files modified in the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
server/main_chatbot.py (1)

406-409: Narrow JSON parse fallback to json.JSONDecodeError (Lines 408, 506).

except Exception is broader than needed for this fallback path and can mask unrelated bugs.

Proposed refactor
-                                        except Exception:
+                                        except json.JSONDecodeError:
                                             tool_input = tool_args
-                                                    except Exception:
+                                                    except json.JSONDecodeError:
                                                         tool_input = tool_args

Also applies to: 504-507

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/main_chatbot.py` around lines 406 - 409, The current broad except
Exception around json.loads should be narrowed to catching json.JSONDecodeError
so unrelated errors aren't swallowed; update the try/except that sets tool_input
from tool_args (the block referencing tool_input and tool_args) to except
json.JSONDecodeError: tool_input = tool_args, and make the same change to the
analogous try/except later (the second occurrence around lines 504-507) so only
JSON parse failures fall back to the original value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@server/utils/db/connection_pool.py`:
- Around line 88-89: Replace the silent broad except in the connection rollback
handler (currently "except BaseException: pass" in connection_pool.py) with a
targeted except Exception that logs the failure (use the module's logger via
logger.exception or logger.error with exception info) and include context about
which connection/transaction failed; also make the same change for the analogous
rollback error handler in db_adapters.py—do not catch BaseException so
KeyboardInterrupt/SystemExit aren’t swallowed, and ensure the log message
includes the exception details for observability.

In `@server/utils/db/db_adapters.py`:
- Around line 148-149: Replace the silent catch-all in the two rollback handlers
that currently use "except BaseException: pass" with a proper "except Exception
as e" that logs the error; locate the rollback handler functions in
server/utils/db/db_adapters.py (the handlers catching BaseException during
rollback) and change the handler to catch Exception and call the module/class
logger (e.g., logger.exception(...) or self._logger.exception(...)) with a clear
message including the exception so rollback failures are recorded.

---

Nitpick comments:
In `@server/main_chatbot.py`:
- Around line 406-409: The current broad except Exception around json.loads
should be narrowed to catching json.JSONDecodeError so unrelated errors aren't
swallowed; update the try/except that sets tool_input from tool_args (the block
referencing tool_input and tool_args) to except json.JSONDecodeError: tool_input
= tool_args, and make the same change to the analogous try/except later (the
second occurrence around lines 504-507) so only JSON parse failures fall back to
the original value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8c046929-e45f-4621-9a14-7cd021b37161

📥 Commits

Reviewing files that changed from the base of the PR and between 10465e8 and 32bde04.

📒 Files selected for processing (3)
  • server/main_chatbot.py
  • server/utils/db/connection_pool.py
  • server/utils/db/db_adapters.py

Comment on lines +88 to 89
except BaseException:
pass
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify broad rollback catch blocks in DB utilities
rg -nP 'except\s+BaseException\s*:' server/utils/db/connection_pool.py server/utils/db/db_adapters.py

Repository: Arvo-AI/aurora

Length of output: 271


🏁 Script executed:

#!/bin/bash
# Get full context around lines 88-89 in connection_pool.py
head -100 server/utils/db/connection_pool.py | tail -40

Repository: Arvo-AI/aurora

Length of output: 1607


🏁 Script executed:

#!/bin/bash
# Get the full function containing the exception handler at line 88
sed -n '70,110p' server/utils/db/connection_pool.py

Repository: Arvo-AI/aurora

Length of output: 1541


🏁 Script executed:

#!/bin/bash
# Check if there's logging setup in the file
rg -n 'import.*logging|logger\s*=' server/utils/db/connection_pool.py

Repository: Arvo-AI/aurora

Length of output: 114


Add logging for rollback failures in connection error handler (Lines 88-89).

The except BaseException: pass silently swallows rollback errors with no observability. This pattern also exists in server/utils/db/db_adapters.py.

Proposed fix
-                except BaseException:
-                    pass
+                except Exception as rollback_error:
+                    logger.warning(
+                        "Rollback failed while handling connection error: %s",
+                        rollback_error,
+                        exc_info=True,
+                    )

Catching BaseException also swallows KeyboardInterrupt, SystemExit, and GeneratorExit. Per coding guidelines, use try/except with logging in Python error handlers.

🧰 Tools
🪛 Ruff (0.15.6)

[error] 88-89: try-except-pass detected, consider logging the exception

(S110)


[warning] 88-88: Do not catch blind exception: BaseException

(BLE001)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/utils/db/connection_pool.py` around lines 88 - 89, Replace the silent
broad except in the connection rollback handler (currently "except
BaseException: pass" in connection_pool.py) with a targeted except Exception
that logs the failure (use the module's logger via logger.exception or
logger.error with exception info) and include context about which
connection/transaction failed; also make the same change for the analogous
rollback error handler in db_adapters.py—do not catch BaseException so
KeyboardInterrupt/SystemExit aren’t swallowed, and ensure the log message
includes the exception details for observability.

Comment on lines +148 to 149
except BaseException:
pass
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n server/utils/db/db_adapters.py | head -50

Repository: Arvo-AI/aurora

Length of output: 2197


🏁 Script executed:

cat -n server/utils/db/db_adapters.py | sed -n '140,180p'

Repository: Arvo-AI/aurora

Length of output: 1243


🏁 Script executed:

wc -l server/utils/db/db_adapters.py

Repository: Arvo-AI/aurora

Length of output: 92


Replace bare except BaseException: pass with except Exception + logging in both rollback handlers (Lines 148–149, 169–170).

Both catch-all handlers silently mask rollback failures without logging. Per coding guidelines, error handling must include logging.

Proposed fixes
             try:
                 connection.rollback()
-            except BaseException:
-                pass
+            except Exception as rollback_error:
+                logger.warning("Admin rollback failed in legacy context manager: %s", rollback_error, exc_info=True)
             try:
                 connection.rollback()
-            except BaseException:
-                pass
+            except Exception as rollback_error:
+                logger.warning("User rollback failed in legacy context manager: %s", rollback_error, exc_info=True)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
except BaseException:
pass
try:
connection.rollback()
except Exception as rollback_error:
logger.warning("Admin rollback failed in legacy context manager: %s", rollback_error, exc_info=True)
🧰 Tools
🪛 Ruff (0.15.6)

[error] 148-149: try-except-pass detected, consider logging the exception

(S110)


[warning] 148-148: Do not catch blind exception: BaseException

(BLE001)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/utils/db/db_adapters.py` around lines 148 - 149, Replace the silent
catch-all in the two rollback handlers that currently use "except BaseException:
pass" with a proper "except Exception as e" that logs the error; locate the
rollback handler functions in server/utils/db/db_adapters.py (the handlers
catching BaseException during rollback) and change the handler to catch
Exception and call the module/class logger (e.g., logger.exception(...) or
self._logger.exception(...)) with a clear message including the exception so
rollback failures are recorded.

Copy link
Copy Markdown
Contributor

@OlivierTrudeau OlivierTrudeau left a comment

Choose a reason for hiding this comment

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

Please just change BaseException to Exception instead. BaseException will have the same behaviour as bar except, but it will now be explicit. The except Exception that you used for main_chatbot.py is the right fix. Thank you for bringing this up!

@beng360 beng360 added the external PR by contributor label Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR by contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants