2016-04-27 08:00:58 -07:00
|
|
|
import sys
|
|
|
|
|
|
|
|
class Error(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Local errors
|
|
|
|
|
2016-09-23 01:04:26 -07:00
|
|
|
class Unregistered(Error):
|
|
|
|
"""Raised when the user requests an item from the registry that does
|
|
|
|
not actually exist.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
class UnregisteredEnv(Unregistered):
|
|
|
|
"""Raised when the user requests an env from the registry that does
|
|
|
|
not actually exist.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
class UnregisteredBenchmark(Unregistered):
|
2016-04-27 08:00:58 -07:00
|
|
|
"""Raised when the user requests an env from the registry that does
|
|
|
|
not actually exist.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2016-05-18 02:23:43 -07:00
|
|
|
class DeprecatedEnv(Error):
|
2016-05-29 09:07:09 -07:00
|
|
|
"""Raised when the user requests an env from the registry with an
|
|
|
|
older version number than the latest env with the same name.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
class UnseedableEnv(Error):
|
|
|
|
"""Raised when the user tries to seed an env that does not support
|
|
|
|
seeding.
|
2016-05-18 02:23:43 -07:00
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2016-04-27 08:00:58 -07:00
|
|
|
class DependencyNotInstalled(Error):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class UnsupportedMode(Exception):
|
|
|
|
"""Raised when the user requests a rendering mode not supported by the
|
|
|
|
environment.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
class ResetNeeded(Exception):
|
|
|
|
"""When the monitor is active, raised when the user tries to step an
|
|
|
|
environment that's already done.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
class ResetNotAllowed(Exception):
|
|
|
|
"""When the monitor is active, raised when the user tries to step an
|
|
|
|
environment that's not yet done.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2016-05-04 11:40:24 +10:00
|
|
|
class InvalidAction(Exception):
|
|
|
|
"""Raised when the user performs an action not contained within the
|
|
|
|
action space
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2016-04-27 08:00:58 -07:00
|
|
|
# API errors
|
|
|
|
|
|
|
|
class APIError(Error):
|
|
|
|
def __init__(self, message=None, http_body=None, http_status=None,
|
|
|
|
json_body=None, headers=None):
|
|
|
|
super(APIError, self).__init__(message)
|
|
|
|
|
|
|
|
if http_body and hasattr(http_body, 'decode'):
|
|
|
|
try:
|
|
|
|
http_body = http_body.decode('utf-8')
|
|
|
|
except:
|
|
|
|
http_body = ('<Could not decode body as utf-8. '
|
|
|
|
'Please report to gym@openai.com>')
|
|
|
|
|
|
|
|
self._message = message
|
|
|
|
self.http_body = http_body
|
|
|
|
self.http_status = http_status
|
|
|
|
self.json_body = json_body
|
|
|
|
self.headers = headers or {}
|
|
|
|
self.request_id = self.headers.get('request-id', None)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
if self.request_id is not None:
|
|
|
|
msg = self._message or "<empty message>"
|
|
|
|
return u"Request {0}: {1}".format(self.request_id, msg)
|
|
|
|
else:
|
|
|
|
return self._message
|
|
|
|
|
|
|
|
if sys.version_info > (3, 0):
|
|
|
|
def __str__(self):
|
|
|
|
return self.__unicode__()
|
|
|
|
else:
|
|
|
|
def __str__(self):
|
|
|
|
return unicode(self).encode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
class APIConnectionError(APIError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class InvalidRequestError(APIError):
|
|
|
|
|
|
|
|
def __init__(self, message, param, http_body=None,
|
|
|
|
http_status=None, json_body=None, headers=None):
|
|
|
|
super(InvalidRequestError, self).__init__(
|
|
|
|
message, http_body, http_status, json_body,
|
|
|
|
headers)
|
|
|
|
self.param = param
|
|
|
|
|
|
|
|
|
|
|
|
class AuthenticationError(APIError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class RateLimitError(APIError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Video errors
|
|
|
|
|
|
|
|
class VideoRecorderError(Error):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class InvalidFrame(Error):
|
|
|
|
pass
|
2016-12-23 16:21:42 -08:00
|
|
|
|
|
|
|
# Wrapper errors
|
|
|
|
|
|
|
|
class DoubleWrapperError(Error):
|
|
|
|
pass
|
2016-12-27 18:28:29 -08:00
|
|
|
|
|
|
|
|
|
|
|
class WrapAfterConfigureError(Error):
|
|
|
|
pass
|
2017-03-05 19:54:09 -08:00
|
|
|
|
|
|
|
|
|
|
|
class RetriesExceededError(Error):
|
|
|
|
pass
|