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

Method __str__

python/ray/exceptions.py:278–341  ·  view source on GitHub ↗

Format a RayTaskError as a string.

(self)

Source from the content-addressed store, hash-verified

276 return self
277
278 def __str__(self):
279 """Format a RayTaskError as a string."""
280 lines = self.traceback_str.strip().split("\n")
281 out = []
282 code_from_internal_file = False
283
284 # Format tracebacks.
285 # Python stacktrace consists of
286 # Traceback...: Indicate the next line will be a traceback.
287 # File [file_name + line number]
288 # code
289 # XError: [message]
290 # NOTE: For _raylet.pyx (Cython), the code is not always included.
291 for i, line in enumerate(lines):
292 # Convert traceback to the readable information.
293 if line.startswith("Traceback "):
294 traceback_line = (
295 f"{colorama.Fore.CYAN}"
296 f"{self.proctitle}()"
297 f"{colorama.Fore.RESET} "
298 f"(pid={self.pid}, ip={self.ip}"
299 )
300 if self.actor_repr:
301 traceback_line += (
302 f", actor_id={self._actor_id}, repr={self.actor_repr})"
303 )
304 else:
305 traceback_line += ")"
306 code_from_internal_file = False
307 out.append(traceback_line)
308 elif line.startswith(" File ") and (
309 "ray/worker.py" in line
310 or "ray/_private/" in line
311 or "ray/util/tracing/" in line
312 or "ray/_raylet.pyx" in line
313 ):
314 # TODO(windows)
315 # Process the internal file line.
316 # The file line always starts with 2 space and File.
317 # https://github.com/python/cpython/blob/0a0a135bae2692d069b18d2d590397fbe0a0d39a/Lib/traceback.py#L421 # noqa
318 if "ray._raylet.raise_if_dependency_failed" in line:
319 # It means the current task is failed
320 # due to the dependency failure.
321 # Print out an user-friendly
322 # message to explain that..
323 out.append(
324 " At least one of the input arguments for "
325 "this task could not be computed:"
326 )
327 if i + 1 < len(lines) and lines[i + 1].startswith(" "):
328 # If the next line is indented with 2 space,
329 # that means it contains internal code information.
330 # For example,
331 # File [file_name] [line]
332 # [code] # if the next line is indented, it is code.
333 # Note there there are 4 spaces in the code line.
334 code_from_internal_file = True
335 elif code_from_internal_file:

Callers

nothing calls this directly

Calls 4

stripMethod · 0.80
splitMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected