How to use the environs.__init__.EnvError function in environs

To help you get started, we’ve selected a few environs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sloria / environs / environs / __init__.py View on Github external
def method(
        self: "Env", name: str, default: typing.Any = ma.missing, subcast: typing.Type = None, **kwargs
    ):
        if self._sealed:
            raise EnvSealedError("Env has already been sealed. New values cannot be parsed.")
        parsed_key, raw_value, proxied_key = self._get_from_environ(name, default)
        if raw_value is ma.missing:
            raise EnvError('Environment variable "{}" not set'.format(proxied_key or parsed_key))
        value = func(raw_value, **kwargs)
        self._fields[parsed_key] = ma.fields.Field(**kwargs)
        self._values[parsed_key] = value
        return value
github sloria / environs / environs / __init__.py View on Github external
FieldType = typing.Type[ma.fields.Field]
FieldOrFactory = typing.Union[FieldType, FieldFactory]
ParserMethod = typing.Callable[..., _T]


class EnvError(ValueError):
    """Raised when an environment variable or if a required environment variable is unset."""


class EnvValidationError(EnvError):
    def __init__(self, message: str, error_messages: typing.Union[ErrorList, ErrorMapping]):
        self.error_messages = error_messages
        super().__init__(message)


class EnvSealedError(TypeError, EnvError):
    pass


class ParserConflictError(ValueError):
    """Raised when adding a custom parser that conflicts with a built-in parser method."""


def _field2method(
    field_or_factory: FieldOrFactory, method_name: str, *, preprocess: typing.Callable = None
) -> ParserMethod:
    def method(
        self: "Env", name: str, default: typing.Any = ma.missing, subcast: Subcast = None, **kwargs
    ) -> _T:
        if self._sealed:
            raise EnvSealedError("Env has already been sealed. New values cannot be parsed.")
        missing = kwargs.pop("missing", None) or default
github sloria / environs / environs / __init__.py View on Github external
_IntType = int

ErrorMapping = typing.Mapping[str, typing.List[str]]
ErrorList = typing.List[str]
FieldFactory = typing.Callable[..., ma.fields.Field]
Subcast = typing.Union[typing.Type, typing.Callable[..., _T]]
FieldType = typing.Type[ma.fields.Field]
FieldOrFactory = typing.Union[FieldType, FieldFactory]
ParserMethod = typing.Callable[..., _T]


class EnvError(ValueError):
    """Raised when an environment variable or if a required environment variable is unset."""


class EnvValidationError(EnvError):
    def __init__(self, message: str, error_messages: typing.Union[ErrorList, ErrorMapping]):
        self.error_messages = error_messages
        super().__init__(message)


class EnvSealedError(TypeError, EnvError):
    pass


class ParserConflictError(ValueError):
    """Raised when adding a custom parser that conflicts with a built-in parser method."""


def _field2method(
    field_or_factory: FieldOrFactory, method_name: str, *, preprocess: typing.Callable = None
) -> ParserMethod: