Skip to content

bring back manual exception printing#5823

Merged
adhami3310 merged 2 commits intomainfrom
bring-back-manual-exception-printing
Sep 25, 2025
Merged

bring back manual exception printing#5823
adhami3310 merged 2 commits intomainfrom
bring-back-manual-exception-printing

Conversation

@adhami3310
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

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.py to detect terminal color support
  • Enhanced compile_or_validate_app() with try/catch exception handling and manual traceback printing
  • Function now returns bool to 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
Loading

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +358 to +362
try:
colorize = _can_colorize()
traceback.print_exception(e, colorize=colorize) # pyright: ignore[reportCallIssue]
except Exception:
traceback.print_exception(e)
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.

style: Manual exception printing instead of using logging violates rule 272ca8d1

Suggested change
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-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Sep 25, 2025

CodSpeed Performance Report

Merging #5823 will not alter performance

Comparing bring-back-manual-exception-printing (29ecd78) with main (a21414d)

Summary

✅ 8 untouched

Copy link
Copy Markdown
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

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

i'm a bit surprised traceback.print_exception doesn't figure out the colorize param on its own...

@adhami3310
Copy link
Copy Markdown
Member Author

i would have used _print_exception_bltin but i think that's pretty new in python

@adhami3310 adhami3310 merged commit 0097e60 into main Sep 25, 2025
39 of 41 checks passed
@adhami3310 adhami3310 deleted the bring-back-manual-exception-printing branch September 25, 2025 17:39
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.

2 participants