Skip to content

ENG-7619: make console errors go to stderr#5789

Merged
adhami3310 merged 2 commits intomainfrom
khaleel/eng-7619-add-checks-for-invalid-computed-vars
Sep 17, 2025
Merged

ENG-7619: make console errors go to stderr#5789
adhami3310 merged 2 commits intomainfrom
khaleel/eng-7619-add-checks-for-invalid-computed-vars

Conversation

@adhami3310
Copy link
Member

No description provided.

@linear
Copy link

linear bot commented Sep 12, 2025

Copy link
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 Summary

This PR improves console error handling in Reflex by implementing proper stderr routing for error messages and enhancing error message clarity. The changes span three key areas:

1. Console Error Routing to stderr (reflex/utils/console.py)
The PR introduces a new _console_stderr instance using Console(stderr=True) and a corresponding _print_stderr() function that mirrors the existing print functionality but routes output to stderr. The critical change is in the error() function, which now uses _print_stderr() instead of the regular print function. This follows Unix conventions where error messages should go to stderr (file descriptor 2) rather than stdout (file descriptor 1), enabling proper separation of program output from error messages for better log handling and shell redirection.

2. Test Updates (tests/units/test_state.py)
The test test_state_with_invalid_yield has been updated to align with the new stderr routing behavior. The test now checks captured.err instead of captured.out for error messages and adds proper type annotations for the capsys parameter. This ensures the test continues to validate error handling correctly after the console routing changes.

3. Computed Variable Error Message Improvements (reflex/vars/base.py)
In the ComputedVar class, error and warning messages now use self._name instead of self._js_expr when displaying the computed variable name. The _name attribute contains the clean Python method name, while _js_expr contains the internal JavaScript expression with markers. This makes error messages more user-friendly by showing readable method names like StateClass.method instead of internal expressions like StateClass.method__reflex_internal_field.

These changes work together to improve the developer experience by providing cleaner error messages and following standard Unix conventions for error output handling. The stderr routing allows users to redirect normal output and error messages independently, which is particularly valuable for logging and debugging workflows.

Confidence score: 5/5

  • This PR is extremely safe to merge with minimal risk of causing production issues
  • Score reflects simple, well-targeted changes that improve standard practices without altering core functionality
  • No files require special attention as all changes are straightforward improvements to existing error handling

3 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 12, 2025

CodSpeed Performance Report

Merging #5789 will not alter performance

Comparing khaleel/eng-7619-add-checks-for-invalid-computed-vars (0141f6a) with main (367b24d)

Summary

✅ 8 untouched

@adhami3310 adhami3310 merged commit f226bb8 into main Sep 17, 2025
41 checks passed
@adhami3310 adhami3310 deleted the khaleel/eng-7619-add-checks-for-invalid-computed-vars branch September 17, 2025 17:02
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