In this article
Ray can preserve an exception through a dual wrapper, expose it only as cause, or replace an unserializable cause; the caller must distinguish those representations.
A caller catches a domain-specific exception locally but misses what appears to be the same failure from a remote Ray task. The worker raised it; the representation crossing the process boundary changed. Classification must inspect the documented wrapper and cause rather than assuming every remote error preserves the original local type.
Record both ends of the failure
Preserve the worker’s declared exception class, serializable diagnostic fields and the caller’s observed exception class. The task fault-tolerance guide describes RayTaskError stored as a failed task result and raised during retrieval or dependency resolution. A downstream task can therefore surface an upstream failure before its own application body runs. Keep that origin distinguishable from a new local failure produced by the consumer itself.
Understand ordinary dual inheritance
When the original exception supports subclassing, the guide describes a returned error that is both RayTaskError and the user’s exception type. A caller’s type-based handler can then work while Ray retains remote context. The exception implementation constructs this dual representation. Do not assume exact class identity or class-name string equality is the supported classification rule; inspect the intended inheritance behavior and available structured fields for the actual runtime.
Handle a non-subclassable cause
Some application exception classes deliberately reject subclass creation. The documented fallback raises RayTaskError alone and leaves the original exception accessible through cause. A handler catching only the domain class can miss this case despite preserved cause information. Define an explicit wrapper path and review the cause under the application’s supported type contract. The failure predicate guide explains why classification must follow the failure representation actually available, rather than an imagined direct exception.
Separate serialization failure from domain failure
The implementation attempts to serialize the cause and can replace it with RayError when that fails, retaining explanatory text. The guide demonstrates an exception containing an unserializable lock. At that point, the caller does not have the original cause object to inspect. Design remote-safe application diagnostics with simple serializable fields. Do not manufacture a domain type from matching message text or assume that a missing structured cause proves the worker never raised the original error.
Exercise the three representations
Use disposable tasks that raise an ordinary domain exception, a non-subclassable exception and an exception with unsupported state. Compare worker origin, caller wrapper, cause and handler outcome. Also pass a failed result as another task’s dependency to verify origin tracking. The process-boundary guide supplies adjacent serialization context. Acceptance requires an understood classification or explicit unresolved outcome for each representation, not merely successful collection of a traceback string.
Keep recovery and evidence separate
Choosing a fallback handler does not authorize retrying an external effect or establish that an error was transient. Preserve task and attempt identity alongside the bounded diagnostic evidence, without copying unrelated application payload into shared logs. The useful result is reliable interpretation of remote failure information under the checked wrapper contract. It is not exact preservation of arbitrary Python objects, a universal message parser or proof that every caller can recover the original exception type after serialization has already discarded it.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.