MCPcopy
hub / github.com/ray-project/ray / as_instanceof_cause

Method as_instanceof_cause

python/ray/exceptions.py:245–276  ·  view source on GitHub ↗

Returns an exception that's an instance of the cause's class. The returned exception inherits from both RayTaskError and the cause class and contains all of the attributes of the cause exception. If the cause class can't be subclassed, issues a warning and returns `

(self)

Source from the content-addressed store, hash-verified

243 return cls(self.cause)
244
245 def as_instanceof_cause(self):
246 """Returns an exception that's an instance of the cause's class.
247
248 The returned exception inherits from both RayTaskError and the
249 cause class and contains all of the attributes of the cause
250 exception.
251
252 If the cause class can't be subclassed, issues a warning and returns `self`.
253 """
254 cause_cls = self.cause.__class__
255 if issubclass(RayTaskError, cause_cls):
256 return self # already satisfied
257
258 try:
259 return self.make_dual_exception_instance()
260 except TypeError as e:
261 logger.warning(
262 f"User exception type {type(self.cause)} in RayTaskError can't"
263 " be subclassed! This exception is raised as"
264 " RayTaskError only. You can use `ray_task_error.cause` to"
265 f" access the user exception. Failure in subclassing: {e}"
266 )
267 return self
268 except Exception as e:
269 logger.warning(
270 "Failed to combine RayTaskError with user exception type "
271 f"{type(self.cause)}; raising RayTaskError only. This can "
272 "happen when the user exception overrides attributes like "
273 "`args` or otherwise blocks subclass construction. "
274 f"Failure in subclassing: {e}"
275 )
276 return self
277
278 def __str__(self):
279 """Format a RayTaskError as a string."""

Callers 10

check_readyMethod · 0.80
get_objectsMethod · 0.80
getFunction · 0.80
test_generator_returnsFunction · 0.80
_process_return_valsFunction · 0.80
__init__Method · 0.80

Calls 2

warningMethod · 0.45