Errors

Everything tickgym raises is a TickGymError, except the plain ValueError or TypeError for an argument that is out of range or of the wrong type before any request is made. All of them pickle, so a worker’s failure crosses a process pool intact.

Three things can go wrong:

  • TICK refused: TickError, from Client and Session calls.

  • The gym refused a request: a GymError with a subclass per ErrorCode. The gym is still usable, and a refused step changed nothing.

  • The connection is gone: TransportError or ProtocolError. The gym is closed, and whether the last request ran is unknown. Open a new gym and reset; the exported record steps it back to where it was.

exception TickGymError

The base class of the SDK’s own errors.

exception TickError(status: int, code: str, message: str)

TICK refused a request, or could not be reached.

status: int

The HTTP status, 0 when the service could not be reached.

code: str

The service’s error code.

message: str

The service’s explanation.

exception GymError(code: ErrorCode, detail: str)

The server refused a request on the gym’s connection.

code: ErrorCode

Which refusal it was.

detail: str

The server’s explanation.

static of(
code: ErrorCode,
detail: str,
) → GymError

The subclass for a code, so callers can catch what they handle.

exception TransportError

The connection failed, timed out, or was already closed. The gym is closed; open a new one and reset.

exception ProtocolError

A frame the client could not read, or an answer of the wrong kind. The gym closes: its state is no longer known.

Refusals

exception BadActionError(code: ErrorCode, detail: str)

An action was refused: its tick is outside the step’s window, its kind is unknown, or its value is out of range.

exception SnapshotUnknownError(code: ErrorCode, detail: str)

The snapshot id names no snapshot of this gym.

exception SnapshotLimitError(code: ErrorCode, detail: str)

The gym holds its maximum number of snapshots; discard one first.

exception CapacityError(code: ErrorCode, detail: str)

The server has no gym slot free; close a gym or wait.

exception SessionUnknownError(code: ErrorCode, detail: str)

The session id names no session: it was closed, or the server restarted.

exception SchemaMismatchError(code: ErrorCode, detail: str)

This package was built for a different server version: use the tickgym that matches the server.

exception ProtocolVersionError(code: ErrorCode, detail: str)

The client and the server speak different protocol versions.

exception BadEntryError(code: ErrorCode, detail: str)

A request body was malformed: a frame or a record the server could not read.

exception InternalError(code: ErrorCode, detail: str)

The server failed while handling the request; the gym is no longer trustworthy.

class ErrorCode(value)
SESSION_UNKNOWN = 1
PROTOCOL_VERSION = 2
SCHEMA_MISMATCH = 3
CAPACITY = 4
SNAPSHOT_UNKNOWN = 5
SNAPSHOT_LIMIT = 6
BAD_ENTRY = 7
BAD_ACTION = 8
INTERNAL = 9
BAD_MESSAGE = 10