Skip to navigation

nemo_gym.utils.exception_inspection

View as Markdown

Read facts from any Python exception: its explicit causes, its type name and its HTTP status.

These functions know nothing about Gym’s failure types; nemo_gym.core.typed_exceptions builds on them.

Module Contents

Functions

NameDescription
bounded_texttext, or its start with TRUNCATION_MARKER when it is longer than max_chars.
error_to_http_statusThe HTTP status error carries as an int: status (aiohttp), status_code (FastAPI, SDKs) or
explicit_causeserror and then each __cause__ (raise ... from), outermost first.
provider_error_reasonThe provider’s own code for an SDK error (OpenSandbox’s error.code, e.g. SANDBOX::ENDED), else the
qualified_type_namemodule.QualName of error’s type; a builtin type is its bare name.
sandbox_failure_prefix[sandbox phase=... provider=... sandbox=... reason=... http=... exit=... signal=... command=...] : what a

Data

TRUNCATION_MARKER

API

nemo_gym.utils.exception_inspection.bounded_text(
text: str,
max_chars: int
) -> str

text, or its start with TRUNCATION_MARKER when it is longer than max_chars.

nemo_gym.utils.exception_inspection.error_to_http_status(
error: BaseException
) -> int | None

The HTTP status error carries as an int: status (aiohttp), status_code (FastAPI, SDKs) or http_status (Gym); None when it carries none.

nemo_gym.utils.exception_inspection.explicit_causes(
error: BaseException
) -> collections.abc.Iterator[BaseException]

error and then each __cause__ (raise ... from), outermost first.

__context__ (an exception that was only being handled, such as a retry’s earlier attempt) is not a cause and is not followed. A cycle stops the walk.

nemo_gym.utils.exception_inspection.provider_error_reason(
error: BaseException
) -> str

The provider’s own code for an SDK error (OpenSandbox’s error.code, e.g. SANDBOX::ENDED), else the error’s type name.

nemo_gym.utils.exception_inspection.qualified_type_name(
error: BaseException
) -> str

module.QualName of error’s type; a builtin type is its bare name.

nemo_gym.utils.exception_inspection.sandbox_failure_prefix(
phase: str,
provider: str | None = None,
sandbox_id: str | None = None,
reason: str | None = None,
http_status: int | None = None,
exit_code: int | None = None,
signal: str | None = None,
command: str | None = None
) -> str

[sandbox phase=... provider=... sandbox=... reason=... http=... exit=... signal=... command=...] : what a producer knows about a sandbox failure, as a fixed-order prefix of its failure_reason, so a saved record says in which phase, on which sandbox and with which provider status it failed. Unknown facts are left out; each value is one bounded token. It decides nothing: no reader classifies a failure from it.

nemo_gym.utils.exception_inspection.TRUNCATION_MARKER = ' [truncated]'