Skip to content

Commit 00cdc4d

Browse files
authored
simplify error handling for first compile (#5628)
* remove sys exception call * remove unneeded code
1 parent 2aa49a9 commit 00cdc4d

File tree

2 files changed

+10
-76
lines changed

2 files changed

+10
-76
lines changed

reflex/reflex.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,9 @@ def _run(
216216
*args,
217217
**kwargs,
218218
)
219-
validation_result = compile_future.result()
219+
compile_future.result()
220220
else:
221-
validation_result = app_task(*args, **kwargs)
222-
223-
if not validation_result:
224-
raise click.exceptions.Exit(1)
221+
app_task(*args, **kwargs)
225222

226223
# Get the frontend and backend commands, based on the environment.
227224
setup_frontend = frontend_cmd = backend_cmd = None

reflex/utils/prerequisites.py

Lines changed: 8 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import functools
88
import importlib
99
import importlib.metadata
10-
import importlib.util
11-
import io
1210
import json
1311
import os
1412
import platform
@@ -498,86 +496,25 @@ def compile_app(
498496
)
499497

500498

501-
def _can_colorize() -> bool:
502-
"""Check if the output can be colorized.
503-
504-
Copied from _colorize.can_colorize.
505-
506-
https://raw.githubusercontent.com/python/cpython/refs/heads/main/Lib/_colorize.py
507-
508-
Returns:
509-
If the output can be colorized
510-
"""
511-
file = sys.stdout
512-
513-
if not sys.flags.ignore_environment:
514-
if os.environ.get("PYTHON_COLORS") == "0":
515-
return False
516-
if os.environ.get("PYTHON_COLORS") == "1":
517-
return True
518-
if os.environ.get("NO_COLOR"):
519-
return False
520-
if os.environ.get("FORCE_COLOR"):
521-
return True
522-
if os.environ.get("TERM") == "dumb":
523-
return False
524-
525-
if not hasattr(file, "fileno"):
526-
return False
527-
528-
if sys.platform == "win32":
529-
try:
530-
import nt
531-
532-
if not nt._supports_virtual_terminal():
533-
return False
534-
except (ImportError, AttributeError):
535-
return False
536-
537-
try:
538-
return os.isatty(file.fileno())
539-
except io.UnsupportedOperation:
540-
return file.isatty()
541-
542-
543499
def compile_or_validate_app(
544500
compile: bool = False,
545501
check_if_schema_up_to_date: bool = False,
546502
prerender_routes: bool = False,
547-
) -> bool:
503+
):
548504
"""Compile or validate the app module based on the default config.
549505
550506
Args:
551507
compile: Whether to compile the app.
552508
check_if_schema_up_to_date: If True, check if the schema is up to date.
553509
prerender_routes: Whether to prerender routes.
554-
555-
Returns:
556-
If the app is compiled successfully.
557510
"""
558-
try:
559-
if compile:
560-
compile_app(
561-
check_if_schema_up_to_date=check_if_schema_up_to_date,
562-
prerender_routes=prerender_routes,
563-
)
564-
else:
565-
validate_app(check_if_schema_up_to_date=check_if_schema_up_to_date)
566-
except Exception as e:
567-
if isinstance(e, click.exceptions.Exit):
568-
return False
569-
570-
import traceback
571-
572-
sys_exception = sys.exception()
573-
574-
try:
575-
colorize = _can_colorize()
576-
traceback.print_exception(e, colorize=colorize) # pyright: ignore[reportCallIssue]
577-
except Exception:
578-
traceback.print_exception(sys_exception)
579-
return False
580-
return True
511+
if compile:
512+
compile_app(
513+
check_if_schema_up_to_date=check_if_schema_up_to_date,
514+
prerender_routes=prerender_routes,
515+
)
516+
else:
517+
validate_app(check_if_schema_up_to_date=check_if_schema_up_to_date)
581518

582519

583520
def get_redis() -> Redis | None:

0 commit comments

Comments
 (0)