From bab1a0dffc86ae5bc13439eb74aa694610ab3dad Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Fri, 22 Dec 2023 21:20:52 -0600 Subject: [PATCH] Call tagify() early to intercept AttributeErrors --- shiny/express/_run.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/shiny/express/_run.py b/shiny/express/_run.py index 34c934d6e..6eea4faeb 100644 --- a/shiny/express/_run.py +++ b/shiny/express/_run.py @@ -39,6 +39,16 @@ def wrap_express_app(file: Path) -> App: ) app_ui = run_express(file) + try: + # We tagify here, instead of waiting for the App object to do it when it wraps + # the UI in a HTMLDocument and calls render() on it. This is because + # AttributeErrors can be thrown during the tagification process, and we need to + # catch them here and convert them to a different type of error, because uvicorn + # specifically catches AttributeErrors and prints an error message that is + # misleading for Shiny Express. https://github.com/posit-dev/py-shiny/issues/937 + app_ui = run_express(file).tagify() + except AttributeError as e: + raise RuntimeError(e) from e def express_server(input: Inputs, output: Outputs, session: Session): try: