Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error message for failed compile_state #4702

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion reflex/compiler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import traceback
from datetime import datetime
from pathlib import Path
from typing import Any, Callable, Dict, Optional, Type, Union
from urllib.parse import urlparse
Expand Down Expand Up @@ -163,8 +165,12 @@ def compile_state(state: Type[BaseState]) -> dict:
try:
initial_state = state(_reflex_internal_init=True).dict(initial=True)
except Exception as e:
timestamp = datetime.now().strftime("%Y-%m-%d__%H-%M-%S")
constants.Reflex.LOGS_DIR.mkdir(parents=True, exist_ok=True)
log_path = constants.Reflex.LOGS_DIR / f"state_compile_error_{timestamp}.log"
traceback.TracebackException.from_exception(e).print(file=log_path.open("w+"))
console.warn(
f"Failed to compile initial state with computed vars, excluding them: {e}"
f"Failed to compile initial state with computed vars. Error log saved to {log_path}"
)
initial_state = state(_reflex_internal_init=True).dict(
initial=True, include_computed=False
Expand Down
2 changes: 2 additions & 0 deletions reflex/constants/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class Reflex(SimpleNamespace):
# If user sets REFLEX_DIR envroment variable use that instead.
DIR = PlatformDirs(MODULE_NAME, False).user_data_path

LOGS_DIR = DIR / "logs"

# The root directory of the reflex library.
ROOT_DIR = Path(__file__).parents[2]

Expand Down
Loading