2022-09-08 10:10:07 +01:00
""" Set of Error classes for gymnasium. """
2022-05-10 15:35:45 +01:00
2016-04-27 08:00:58 -07:00
class Error ( Exception ) :
2022-05-10 15:35:45 +01:00
""" Error superclass. """
2016-04-27 08:00:58 -07:00
2021-07-29 02:26:34 +02:00
2023-11-28 16:25:20 +00:00
# Registration errors
class UnregisteredEnv ( Error ) :
2022-05-10 15:35:45 +01:00
""" Raised when the user requests an env from the registry that does not actually exist. """
2016-09-23 01:04:26 -07:00
2021-07-29 02:26:34 +02:00
2022-01-19 13:50:25 -05:00
class NamespaceNotFound ( UnregisteredEnv ) :
2022-05-10 15:35:45 +01:00
""" Raised when the user requests an env from the registry where the namespace doesn ' t exist. """
2022-01-19 13:50:25 -05:00
class NameNotFound ( UnregisteredEnv ) :
2022-05-10 15:35:45 +01:00
""" Raised when the user requests an env from the registry where the name doesn ' t exist. """
2022-01-19 13:50:25 -05:00
class VersionNotFound ( UnregisteredEnv ) :
2022-05-10 15:35:45 +01:00
""" Raised when the user requests an env from the registry where the version doesn ' t exist. """
2022-01-19 13:50:25 -05:00
2016-05-18 02:23:43 -07:00
class DeprecatedEnv ( Error ) :
2022-05-10 15:35:45 +01:00
""" Raised when the user requests an env from the registry with an older version number than the latest env with the same name. """
2016-05-29 09:07:09 -07:00
2021-07-29 02:26:34 +02:00
2022-01-19 13:50:25 -05:00
class RegistrationError ( Error ) :
2022-05-10 15:35:45 +01:00
""" Raised when the user attempts to register an invalid env. For example, an unversioned env when a versioned env exists. """
2022-01-19 13:50:25 -05:00
2023-11-28 16:25:20 +00:00
# Environment errors
2016-04-27 08:00:58 -07:00
class DependencyNotInstalled ( Error ) :
2022-05-10 15:35:45 +01:00
""" Raised when the user has not installed a dependency. """
2016-04-27 08:00:58 -07:00
2021-07-29 02:26:34 +02:00
2022-05-10 15:35:45 +01:00
class UnsupportedMode ( Error ) :
""" Raised when the user requests a rendering mode not supported by the environment. """
2021-07-29 02:26:34 +02:00
2016-04-27 08:00:58 -07:00
2022-11-28 14:34:32 +01:00
class InvalidMetadata ( Error ) :
""" Raised when the metadata of an environment is not valid. """
2022-05-10 15:35:45 +01:00
class ResetNeeded ( Error ) :
""" When the order enforcing is violated, i.e. step or render is called before reset. """
2021-07-29 02:26:34 +02:00
2022-05-10 15:35:45 +01:00
class InvalidAction ( Error ) :
""" Raised when the user performs an action not contained within the action space. """
2016-05-04 11:40:24 +10:00
2021-07-29 02:26:34 +02:00
2022-10-20 11:30:14 +02:00
class MissingArgument ( Error ) :
""" Raised when a required argument in the initializer is missing. """
2022-12-02 01:04:34 +01:00
class InvalidProbability ( Error ) :
""" Raised when given an invalid value for a probability. """
2022-11-20 00:57:10 +01:00
class InvalidBound ( Error ) :
""" Raised when the clipping an array with invalid upper and/or lower bound. """
2016-12-23 16:21:42 -08:00
# Wrapper errors
2023-04-16 13:04:55 +02:00
class DeprecatedWrapper ( ImportError ) :
""" Error message for importing an old version of a wrapper. """
2019-06-21 17:29:44 -04:00
# Vectorized environments errors
class AlreadyPendingCallError ( Exception ) :
2022-05-10 15:35:45 +01:00
""" Raised when `reset`, or `step` is called asynchronously (e.g. with `reset_async`, or `step_async` respectively), and `reset_async`, or `step_async` (respectively) is called again (without a complete call to `reset_wait`, or `step_wait` respectively). """
def __init__ ( self , message : str , name : str ) :
""" Initialises the exception with name attributes. """
2021-11-14 14:50:40 +01:00
super ( ) . __init__ ( message )
2019-06-21 17:29:44 -04:00
self . name = name
2021-07-29 02:26:34 +02:00
2019-06-21 17:29:44 -04:00
class NoAsyncCallError ( Exception ) :
2022-05-10 15:35:45 +01:00
""" Raised when an asynchronous `reset`, or `step` is not running, but `reset_wait`, or `step_wait` (respectively) is called. """
2021-07-29 02:26:34 +02:00
2022-05-10 15:35:45 +01:00
def __init__ ( self , message : str , name : str ) :
""" Initialises the exception with name attributes. """
2021-11-14 14:50:40 +01:00
super ( ) . __init__ ( message )
2019-06-21 17:29:44 -04:00
self . name = name
2021-07-29 02:26:34 +02:00
2019-06-21 17:29:44 -04:00
class ClosedEnvironmentError ( Exception ) :
2022-05-10 15:35:45 +01:00
""" Trying to call `reset`, or `step`, while the environment is closed. """
2020-09-21 22:38:51 +02:00
2021-07-29 02:26:34 +02:00
2020-09-21 22:38:51 +02:00
class CustomSpaceError ( Exception ) :
2022-09-08 10:10:07 +01:00
""" The space is a custom gymnasium.Space instance, and is not supported by `AsyncVectorEnv` with `shared_memory=True`. """