bring back manual exception printing#5823
Conversation
There was a problem hiding this comment.
Greptile Overview
Summary
Restores manual exception printing functionality that allows colorized traceback output when app compilation or validation fails. The changes modify compile_or_validate_app to return a boolean success indicator and catch exceptions to print them directly using Python's traceback.print_exception() with color support detection.
Key changes:
- Modified
_run()function to check return value and exit with error code on failure - Added
_can_colorize()function copied from CPython's_colorize.pyto detect terminal color support - Enhanced
compile_or_validate_app()with try/catch exception handling and manual traceback printing - Function now returns
boolto indicate success/failure status
Confidence Score: 4/5
- This PR is safe to merge with minimal risk as it primarily adds error handling and improves user experience
- Score reflects well-implemented functionality but minor style guideline deviation with direct print statements instead of logging
- Pay attention to reflex/utils/prerequisites.py for potential logging improvements
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| reflex/reflex.py | 4/5 | Modified to capture return value from app compilation and exit with error code on failure |
| reflex/utils/prerequisites.py | 3/5 | Added manual exception printing with colorization support, but uses print statements instead of logging |
Sequence Diagram
sequenceDiagram
participant CLI as Reflex CLI (_run)
participant Task as app_task (compile_or_validate_app)
participant Validation as get_and_validate_app / get_compiled_app
participant Exception as Exception Handler
CLI->>Task: Call compile_or_validate_app()
alt compile=True
Task->>Validation: get_compiled_app()
Validation-->>Task: Returns app module
else compile=False
Task->>Validation: get_and_validate_app()
Validation-->>Task: Returns AppInfo
end
alt Success
Task-->>CLI: return True
CLI->>CLI: Continue with app execution
else Exception occurs
Validation->>Exception: Raises Exception
Exception->>Exception: _can_colorize() check
Exception->>Exception: traceback.print_exception(e, colorize=colorize)
Exception-->>Task: return False
Task-->>CLI: return False
CLI->>CLI: raise SystemExit(1)
end
2 files reviewed, 1 comment
| try: | ||
| colorize = _can_colorize() | ||
| traceback.print_exception(e, colorize=colorize) # pyright: ignore[reportCallIssue] | ||
| except Exception: | ||
| traceback.print_exception(e) |
There was a problem hiding this comment.
style: Manual exception printing instead of using logging violates rule 272ca8d1
| try: | |
| colorize = _can_colorize() | |
| traceback.print_exception(e, colorize=colorize) # pyright: ignore[reportCallIssue] | |
| except Exception: | |
| traceback.print_exception(e) | |
| try: | |
| colorize = _can_colorize() | |
| console.debug("Exception occurred during app compilation/validation:") | |
| traceback.print_exception(e, colorize=colorize) # pyright: ignore[reportCallIssue] | |
| except Exception: | |
| console.debug("Exception occurred during app compilation/validation:") | |
| traceback.print_exception(e) |
Context Used: Rule - Use logging instead of print statements for debugging or informational output in Python files. (link)
CodSpeed Performance ReportMerging #5823 will not alter performanceComparing Summary
|
masenf
left a comment
There was a problem hiding this comment.
i'm a bit surprised traceback.print_exception doesn't figure out the colorize param on its own...
|
i would have used |
No description provided.