add custom error
This commit is contained in:
parent
71033413a1
commit
fe0a791efb
@ -12,7 +12,7 @@ from typing import Any, Dict, List, Optional, Set, Union
|
|||||||
|
|
||||||
from typing_extensions import get_type_hints
|
from typing_extensions import get_type_hints
|
||||||
|
|
||||||
from reflex.utils.exceptions import ConfigError
|
from reflex.utils.exceptions import ConfigError, EnvironmentVarValueError
|
||||||
from reflex.utils.types import value_inside_optional
|
from reflex.utils.types import value_inside_optional
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -167,7 +167,7 @@ def interpret_boolean_env(value: str) -> bool:
|
|||||||
The interpreted value.
|
The interpreted value.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: If the value is invalid.
|
EnvironmentVarValueError: If the value is invalid.
|
||||||
"""
|
"""
|
||||||
true_values = ["true", "1", "yes", "y"]
|
true_values = ["true", "1", "yes", "y"]
|
||||||
false_values = ["false", "0", "no", "n"]
|
false_values = ["false", "0", "no", "n"]
|
||||||
@ -176,8 +176,7 @@ def interpret_boolean_env(value: str) -> bool:
|
|||||||
return True
|
return True
|
||||||
elif value.lower() in false_values:
|
elif value.lower() in false_values:
|
||||||
return False
|
return False
|
||||||
else:
|
raise EnvironmentVarValueError(f"Invalid boolean value: {value}")
|
||||||
raise ValueError(f"Invalid boolean value: {value}")
|
|
||||||
|
|
||||||
|
|
||||||
def interpret_int_env(value: str) -> int:
|
def interpret_int_env(value: str) -> int:
|
||||||
@ -190,12 +189,12 @@ def interpret_int_env(value: str) -> int:
|
|||||||
The interpreted value.
|
The interpreted value.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: If the value is invalid.
|
EnvironmentVarValueError: If the value is invalid.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return int(value)
|
return int(value)
|
||||||
except ValueError as ve:
|
except ValueError as ve:
|
||||||
raise ValueError(f"Invalid integer value: {value}") from ve
|
raise EnvironmentVarValueError(f"Invalid integer value: {value}") from ve
|
||||||
|
|
||||||
|
|
||||||
def interpret_path_env(value: str) -> Path:
|
def interpret_path_env(value: str) -> Path:
|
||||||
@ -206,8 +205,14 @@ def interpret_path_env(value: str) -> Path:
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The interpreted value.
|
The interpreted value.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
EnvironmentVarValueError: If the path does not exist.
|
||||||
"""
|
"""
|
||||||
return Path(value)
|
path = Path(value)
|
||||||
|
if not path.exists():
|
||||||
|
raise EnvironmentVarValueError(f"Path does not exist: {path}")
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
def interpret_env_var_value(value: str, field: dataclasses.Field) -> Any:
|
def interpret_env_var_value(value: str, field: dataclasses.Field) -> Any:
|
||||||
|
@ -135,3 +135,7 @@ class SetUndefinedStateVarError(ReflexError, AttributeError):
|
|||||||
|
|
||||||
class StateSchemaMismatchError(ReflexError, TypeError):
|
class StateSchemaMismatchError(ReflexError, TypeError):
|
||||||
"""Raised when the serialized schema of a state class does not match the current schema."""
|
"""Raised when the serialized schema of a state class does not match the current schema."""
|
||||||
|
|
||||||
|
|
||||||
|
class EnvironmentVarValueError(ReflexError, ValueError):
|
||||||
|
"""Raised when an environment variable is set to an invalid value."""
|
||||||
|
Loading…
Reference in New Issue
Block a user