Prevent logging rollover errors from corrupting the TUI#116
Conversation
📝 WalkthroughWalkthroughAdds ChangesSafe logging reconfiguration
Sequence Diagram(s)sequenceDiagram
participant SafeRotatingFileHandler
participant RotatingFileHandler
participant logging
SafeRotatingFileHandler->>RotatingFileHandler: doRollover()
RotatingFileHandler-->>SafeRotatingFileHandler: FileNotFoundError
SafeRotatingFileHandler->>SafeRotatingFileHandler: recreate base stream
SafeRotatingFileHandler->>logging: handleError() with raiseExceptions disabled
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/ecli/utils/logging_config.py`:
- Around line 80-83: The handleError method in Logging-related code has a
redundant trailing return after already declaring a None return type and
deleting the unused record parameter. Remove the explicit return from
handleError in the logging_config module so the method ends after del record,
keeping the suppression behavior unchanged.
- Around line 70-78: The doRollover method in the logging handler has duplicate
exception handling because FileNotFoundError is already covered by OSError, and
both branches call _recover_base_stream(). Simplify the rollover logic by
keeping a single except OSError branch in doRollover and routing all recovery
through _recover_base_stream(), using the existing _rollover_lock and superclass
call unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 6bf42151-9eed-46c0-a837-758ae98b1f9d
📒 Files selected for processing (2)
src/ecli/utils/logging_config.pytests/utils/test_logging_config.py
| def doRollover(self) -> None: | ||
| """Perform rollover with in-process serialization and recovery.""" | ||
| with self._rollover_lock: | ||
| try: | ||
| super().doRollover() | ||
| except FileNotFoundError: | ||
| self._recover_base_stream() | ||
| except OSError: | ||
| self._recover_base_stream() |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
Collapse the duplicate except branches.
FileNotFoundError is a subclass of OSError, and both handlers invoke the same _recover_base_stream(). The separate branch is dead and can be merged for clarity.
♻️ Proposed simplification
with self._rollover_lock:
try:
super().doRollover()
- except FileNotFoundError:
- self._recover_base_stream()
except OSError:
self._recover_base_stream()📝 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.
| def doRollover(self) -> None: | |
| """Perform rollover with in-process serialization and recovery.""" | |
| with self._rollover_lock: | |
| try: | |
| super().doRollover() | |
| except FileNotFoundError: | |
| self._recover_base_stream() | |
| except OSError: | |
| self._recover_base_stream() | |
| def doRollover(self) -> None: | |
| """Perform rollover with in-process serialization and recovery.""" | |
| with self._rollover_lock: | |
| try: | |
| super().doRollover() | |
| except OSError: | |
| self._recover_base_stream() |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/ecli/utils/logging_config.py` around lines 70 - 78, The doRollover method
in the logging handler has duplicate exception handling because
FileNotFoundError is already covered by OSError, and both branches call
_recover_base_stream(). Simplify the rollover logic by keeping a single except
OSError branch in doRollover and routing all recovery through
_recover_base_stream(), using the existing _rollover_lock and superclass call
unchanged.
| def handleError(self, record: logging.LogRecord) -> None: | ||
| """Suppress logging-internal stderr writes during curses runtime.""" | ||
| del record | ||
| return |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
Drop the redundant trailing return.
The explicit return at the end of a None-returning method is superfluous (SonarCloud). The del record already documents the intentionally-unused parameter.
♻️ Proposed cleanup
def handleError(self, record: logging.LogRecord) -> None:
"""Suppress logging-internal stderr writes during curses runtime."""
del record
- return📝 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.
| def handleError(self, record: logging.LogRecord) -> None: | |
| """Suppress logging-internal stderr writes during curses runtime.""" | |
| del record | |
| return | |
| def handleError(self, record: logging.LogRecord) -> None: | |
| """Suppress logging-internal stderr writes during curses runtime.""" | |
| del record |
🧰 Tools
🪛 GitHub Check: SonarCloud Code Analysis
[warning] 83-83: Remove this redundant return.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/ecli/utils/logging_config.py` around lines 80 - 83, The handleError
method in Logging-related code has a redundant trailing return after already
declaring a None return type and deleting the unused record parameter. Remove
the explicit return from handleError in the logging_config module so the method
ends after del record, keeping the suppression behavior unchanged.
Source: Linters/SAST tools
|



This PR fixes a runtime logging failure where RotatingFileHandler rollover errors could print Python logging tracebacks directly into the curses TUI.
Changes:
Validation:
Manual smoke:
Non-goals:
Summary by CodeRabbit