From 5168d8164ed85e5997fe8f0407b35dabb2b931ff Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Tue, 5 Nov 2024 11:37:39 -0800 Subject: [PATCH] better missing system package message --- reflex/constants/__init__.py | 2 ++ reflex/constants/base.py | 2 ++ reflex/utils/exceptions.py | 24 ++++++++++++++++++++++++ reflex/utils/prerequisites.py | 13 ++++++------- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/reflex/constants/__init__.py b/reflex/constants/__init__.py index a540805b5..5a1e506e0 100644 --- a/reflex/constants/__init__.py +++ b/reflex/constants/__init__.py @@ -5,6 +5,8 @@ from .base import ( ENV_BACKEND_ONLY_ENV_VAR, ENV_FRONTEND_ONLY_ENV_VAR, ENV_MODE_ENV_VAR, + IS_LINUX, + IS_MACOS, IS_WINDOWS, LOCAL_STORAGE, POLLING_MAX_HTTP_BUFFER_SIZE, diff --git a/reflex/constants/base.py b/reflex/constants/base.py index bba53d625..9e2bae20b 100644 --- a/reflex/constants/base.py +++ b/reflex/constants/base.py @@ -13,6 +13,8 @@ from platformdirs import PlatformDirs from .utils import classproperty IS_WINDOWS = platform.system() == "Windows" +IS_MACOS = platform.system() == "Darwin" +IS_LINUX = platform.system() == "Linux" class Dirs(SimpleNamespace): diff --git a/reflex/utils/exceptions.py b/reflex/utils/exceptions.py index 661f29095..446d30fce 100644 --- a/reflex/utils/exceptions.py +++ b/reflex/utils/exceptions.py @@ -1,5 +1,7 @@ """Custom Exceptions.""" +from typing import NoReturn + class ReflexError(Exception): """Base exception for all Reflex exceptions.""" @@ -151,3 +153,25 @@ class DynamicComponentInvalidSignature(ReflexError, TypeError): class InvalidPropValueError(ReflexError): """Raised when a prop value is invalid.""" + + +class SystemPackageMissingError(ReflexError): + """Raised when a system package is missing.""" + + +def raise_system_package_missing_error(package: str) -> NoReturn: + """Raise a SystemPackageMissingError. + + Args: + package: The name of the missing system package. + + Raises: + SystemPackageMissingError: The raised exception. + """ + from reflex.constants import IS_MACOS + + raise SystemPackageMissingError( + f"System package '{package}' is missing." + " Please install it through your system package manager." + + (f" You can do so by running 'brew install {package}'." if IS_MACOS else "") + ) diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index aba7714af..4a24da0b5 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -35,7 +35,10 @@ from reflex import constants, model from reflex.compiler import templates from reflex.config import Config, environment, get_config from reflex.utils import console, net, path_ops, processes -from reflex.utils.exceptions import GeneratedCodeHasNoFunctionDefs +from reflex.utils.exceptions import ( + GeneratedCodeHasNoFunctionDefs, + raise_system_package_missing_error, +) from reflex.utils.format import format_library_name from reflex.utils.registry import _get_npm_registry @@ -820,11 +823,7 @@ def install_node(): def install_bun(): - """Install bun onto the user's system. - - Raises: - FileNotFoundError: If required packages are not found. - """ + """Install bun onto the user's system.""" win_supported = is_windows_bun_supported() one_drive_in_path = windows_check_onedrive_in_path() if constants.IS_WINDOWS and not win_supported or one_drive_in_path: @@ -863,7 +862,7 @@ def install_bun(): else: unzip_path = path_ops.which("unzip") if unzip_path is None: - raise FileNotFoundError("Reflex requires unzip to be installed.") + raise_system_package_missing_error("unzip") # Run the bun install script. download_and_run(