better missing system package message (#4306)

* better missing system package message

* change error type
This commit is contained in:
Khaleel Al-Adhami 2024-11-06 09:21:04 -08:00 committed by GitHub
parent 6334cfab0d
commit bfa7ca639f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 9 deletions

View File

@ -2,6 +2,8 @@
from .base import (
COOKIES,
IS_LINUX,
IS_MACOS,
IS_WINDOWS,
LOCAL_STORAGE,
POLLING_MAX_HTTP_BUFFER_SIZE,

View File

@ -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):

View File

@ -1,5 +1,7 @@
"""Custom Exceptions."""
from typing import NoReturn
class ReflexError(Exception):
"""Base exception for all Reflex exceptions."""
@ -147,3 +149,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 "")
)

View File

@ -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(

View File

@ -19,7 +19,7 @@ from reflex.utils import (
types,
)
from reflex.utils import exec as utils_exec
from reflex.utils.exceptions import ReflexError
from reflex.utils.exceptions import ReflexError, SystemPackageMissingError
from reflex.vars.base import Var
@ -503,7 +503,7 @@ def test_bun_install_without_unzip(mocker):
mocker.patch("pathlib.Path.exists", return_value=False)
mocker.patch("reflex.utils.prerequisites.constants.IS_WINDOWS", False)
with pytest.raises(FileNotFoundError):
with pytest.raises(SystemPackageMissingError):
prerequisites.install_bun()