@@ -278,6 +278,22 @@ def windows_npm_escape_hatch() -> bool:
278278 return environment .REFLEX_USE_NPM .get ()
279279
280280
281+ def _check_app_name (config : Config ):
282+ """Check if the app name is set in the config.
283+
284+ Args:
285+ config: The config object.
286+
287+ Raises:
288+ RuntimeError: If the app name is not set in the config.
289+ """
290+ if not config .app_name :
291+ raise RuntimeError (
292+ "Cannot get the app module because `app_name` is not set in rxconfig! "
293+ "If this error occurs in a reflex test case, ensure that `get_app` is mocked."
294+ )
295+
296+
281297def get_app (reload : bool = False ) -> ModuleType :
282298 """Get the app module based on the default config.
283299
@@ -288,18 +304,16 @@ def get_app(reload: bool = False) -> ModuleType:
288304 The app based on the default config.
289305
290306 Raises:
291- RuntimeError : If the app name is not set in the config .
307+ Exception : If an error occurs while getting the app module .
292308 """
293309 from reflex .utils import telemetry
294310
295311 try :
296312 environment .RELOAD_CONFIG .set (reload )
297313 config = get_config ()
298- if not config .app_name :
299- raise RuntimeError (
300- "Cannot get the app module because `app_name` is not set in rxconfig! "
301- "If this error occurs in a reflex test case, ensure that `get_app` is mocked."
302- )
314+
315+ _check_app_name (config )
316+
303317 module = config .module
304318 sys .path .insert (0 , str (Path .cwd ()))
305319 app = (
@@ -315,11 +329,11 @@ def get_app(reload: bool = False) -> ModuleType:
315329
316330 # Reload the app module.
317331 importlib .reload (app )
318-
319- return app
320332 except Exception as ex :
321333 telemetry .send_error (ex , context = "frontend" )
322334 raise
335+ else :
336+ return app
323337
324338
325339def get_and_validate_app (reload : bool = False ) -> AppInfo :
@@ -1189,11 +1203,12 @@ def ensure_reflex_installation_id() -> Optional[int]:
11891203 if installation_id is None :
11901204 installation_id = random .getrandbits (128 )
11911205 installation_id_file .write_text (str (installation_id ))
1192- # If we get here, installation_id is definitely set
1193- return installation_id
11941206 except Exception as e :
11951207 console .debug (f"Failed to ensure reflex installation id: { e } " )
11961208 return None
1209+ else :
1210+ # If we get here, installation_id is definitely set
1211+ return installation_id
11971212
11981213
11991214def initialize_reflex_user_directory ():
@@ -1407,19 +1422,22 @@ def create_config_init_app_from_remote_template(app_name: str, template_url: str
14071422 except OSError as ose :
14081423 console .error (f"Failed to create temp directory for extracting zip: { ose } " )
14091424 raise typer .Exit (1 ) from ose
1425+
14101426 try :
14111427 zipfile .ZipFile (zip_file_path ).extractall (path = unzip_dir )
14121428 # The zip file downloaded from github looks like:
14131429 # repo-name-branch/**/*, so we need to remove the top level directory.
1414- if len (subdirs := os .listdir (unzip_dir )) != 1 :
1415- console .error (f"Expected one directory in the zip, found { subdirs } " )
1416- raise typer .Exit (1 )
1417- template_dir = unzip_dir / subdirs [0 ]
1418- console .debug (f"Template folder is located at { template_dir } " )
14191430 except Exception as uze :
14201431 console .error (f"Failed to unzip the template: { uze } " )
14211432 raise typer .Exit (1 ) from uze
14221433
1434+ if len (subdirs := os .listdir (unzip_dir )) != 1 :
1435+ console .error (f"Expected one directory in the zip, found { subdirs } " )
1436+ raise typer .Exit (1 )
1437+
1438+ template_dir = unzip_dir / subdirs [0 ]
1439+ console .debug (f"Template folder is located at { template_dir } " )
1440+
14231441 # Move the rxconfig file here first.
14241442 path_ops .mv (str (template_dir / constants .Config .FILE ), constants .Config .FILE )
14251443 new_config = get_config (reload = True )
0 commit comments