o
    `۷i?                     @   sL  d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlZd dl	m
  mZ d dlmZ d dlmZmZmZ d dlmZmZmZmZmZmZmZ d dlmZmZ e eZ eG dd de!Z"eG d	d
 d
e"Z#eG dd de"Z$eG dd de"Z%eG dd de"Z&eG dd de"Z'eG dd de"Z(eG dd de(Z)eG dd de(Z*eG dd de"Z+eG dd de"Z,eG dd de"Z-eG dd  d e"Z.eG d!d" d"e"Z/eG d#d$ d$e"Z0eG d%d& d&e"Z1eG d'd( d(e"Z2eG d)d* d*e2Z3eG d+d, d,e"Z4eG d-d. d.e2e5Z6eG d/d0 d0e2Z7eG d1d2 d2e2Z8eG d3d4 d4e2Z9eG d5d6 d6e"e:Z;eG d7d8 d8e"Z<eG d9d: d:e"Z=eG d;d< d<e"Z>eG d=d> d>e"Z?eG d?d@ d@e"Z@eG dAdB dBe"ZAeG dCdD dDe"ZBeG dEdF dFe"ZCeG dGdH dHe"ZDeG dIdJ dJe"ZEedKdLG dMdN dNe+ZFedKdLG dOdP dPeFe:ZGedKdLG dQdR dRe+ZHedKdLG dSdT dTe+ZIedKdLG dUdV dVe"ZJeG dWdX dXeKe"ZLeG dYdZ dZeKe"ZMe<e"e%e'e(e.e2e3e6e9e8e;e=e>e?e@eAe&eBe)eCe*eFeGeEeHeJeLeMe,gZNdS )[    N)format_exception)OptionalUnion)ActorIDTaskIDWorkerID)PYTHONActorDiedErrorContextAddress	ErrorTypeLanguageNodeDeathInfoRayException)DeveloperAPI	PublicAPIc                   @   s0   e Zd ZdZdd Zedd Zedd ZdS )	RayErrorz'Super class of all ray exception types.c                 C   s6   t | | | jf}dt| }ttt| |d S )N
)languageserialized_exceptionformatted_exception_string)	type__traceback__joinr   r   r   pickledumpsSerializeToString)selfexc_infor    r   D/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/exceptions.pyto_bytes   s   zRayError.to_bytesc                 C   s   t  }||  t|S N)r   ParseFromStringr   from_ray_exception)bray_exceptionr   r   r   
from_bytes(   s   

zRayError.from_bytesc                 C   sH   | j tkr zt| jW S  ty   t| dd}t| Y S w t| S )Nr   z(No formatted exception string available.)	r   r   r   loadsr   	ExceptiongetattrUnserializableExceptionCrossLanguageError)r%   original_stacktracer   r   r   r#   .   s   
zRayError.from_ray_exceptionN)__name__
__module____qualname____doc__r    staticmethodr&   r#   r   r   r   r   r      s    

r   c                           e Zd ZdZ fddZ  ZS )r+   zRaised from another language.c                    s"   t  dt|j|j d S )NzAn exception raised from {}:
{})super__init__formatr   Namer   r   )r   r%   	__class__r   r   r4   E   s   
zCrossLanguageError.__init__)r-   r.   r/   r0   r4   __classcell__r   r   r7   r   r+   A   s    r+   c                   @   s6   e Zd ZdZ	d	dee dee fddZdd ZdS )
TaskCancelledErrorzRaised when this task is cancelled.

    Args:
        task_id: The TaskID of the function that was directly
            cancelled.
    Ntask_iderror_messagec                 C      || _ || _d S r!   )r;   r<   )r   r;   r<   r   r   r   r4   W   s   
zTaskCancelledError.__init__c                 C   s0   d}| j rdt| j  d }| jr|| j7 }|S )N zTask: z was cancelled. )r;   strr<   r   msgr   r   r   __str__]   s   
zTaskCancelledError.__str__)NN)	r-   r.   r/   r0   r   r   r?   r4   rB   r   r   r   r   r:   N   s    
r:   c                   @   sR   e Zd ZdZ					dddZdddZddd	Zdd
dZdd Zdd Z	dS )RayTaskErrora  Indicates that a task threw an exception during execution.

    If a task throws an exception during execution, a RayTaskError is stored in
    the object store for each of the task's outputs. When an object is
    retrieved from the object store, the Python method that retrieved it checks
    to see if the object is a RayTaskError and if it is then an exception is
    thrown propagating the error message.
    Nc	              
   C   s  ddl }	|r
|| _n|	j | _|pt | _|p|	j | _	|| _
|| _|| _|| _|| _zt| W n9 tjtfyn }
 z*|jj d|jj }d| d|
 d| }td| d t|| _W Y d}
~
nd}
~
ww ||| j|||f| _|dusJ dS )	zInitialize a RayTaskError.r   N.z
Exception z isn't serializable: z.
Original exception details:
z(The original cause of the RayTaskError (z) isn't serializable.)ray	proctitle_rayletgetproctitleosgetpidpidutilget_node_ip_addressipfunction_nametraceback_str
actor_repr	_actor_idcauser   r   PicklingError	TypeErrorr8   r.   r-   logger	exceptionr   args)r   rO   rP   rS   rF   rK   rN   rQ   actor_idrE   eerr_typeerr_msgr   r   r   r4   q   s6   
zRayTaskError.__init__returnc                 C   s&   t jdkrt| jtr|  S |  S )zMakes a object instance that inherits from both RayTaskError and the type of
        `self.cause`. Raises TypeError if the cause class can't be subclassed)      )sysversion_info
isinstancerS   ExceptionGroup,_make_exceptiongroup_dual_exception_instance$_make_normal_dual_exception_instancer   r   r   r   make_dual_exception_instance   s
   z)RayTaskError.make_dual_exception_instancec                    L   | j j}t| G  fdddt| d|j d}| _| _ | j S )Nc                       sN   e Zd Zdd Zedd Zejdd Z fddZdd	 Zfd
dZ	dS )z>RayTaskError._make_normal_dual_exception_instance.<locals>.clsc                 S      || _ |f| _d S r!   rS   _ray_task_error_argsr   rS   r   r   r   r4      s   zGRayTaskError._make_normal_dual_exception_instance.<locals>.cls.__init__c                 S      | j S r!   rk   rf   r   r   r   rX         zCRayTaskError._make_normal_dual_exception_instance.<locals>.cls.argsc                 S   
   || _ d S r!   rn   r   valuer   r   r   rX         
c                    
    | j fS r!   rn   rf   clsr   r   
__reduce__      
zIRayTaskError._make_normal_dual_exception_instance.<locals>.cls.__reduce__c                 S      t | j|S r!   r)   rS   r   namer   r   r   __getattr__      zJRayTaskError._make_normal_dual_exception_instance.<locals>.cls.__getattr__c                        S r!   r   rf   	error_msgr   r   rB         zFRayTaskError._make_normal_dual_exception_instance.<locals>.cls.__str__N)
r-   r.   r/   r4   propertyrX   setterrw   r}   rB   r   rv   r   r   r   rv      s    

rv   RayTaskError()rS   r8   r?   rC   r-   r/   r   	cause_clsr|   r   r   r   re      s   
z1RayTaskError._make_normal_dual_exception_instancec                    rh   )Nc                       s^   e Zd Z fddZdd Zedd Zejdd Zfdd	Zd
d Z	fddZ
  ZS )zFRayTaskError._make_exceptiongroup_dual_exception_instance.<locals>.clsc                    s   t  | |j|j}|S r!   )r3   __new__message
exceptions)rv   rS   r   r7   r   r   r      s   zNRayTaskError._make_exceptiongroup_dual_exception_instance.<locals>.cls.__new__c                 S   ri   r!   rj   rl   r   r   r   r4      s   zORayTaskError._make_exceptiongroup_dual_exception_instance.<locals>.cls.__init__c                 S   rm   r!   rn   rf   r   r   r   rX      ro   zKRayTaskError._make_exceptiongroup_dual_exception_instance.<locals>.cls.argsc                 S   rp   r!   rn   rq   r   r   r   rX      rs   c                    rt   r!   rn   rf   ru   r   r   rw      rx   zQRayTaskError._make_exceptiongroup_dual_exception_instance.<locals>.cls.__reduce__c                 S   ry   r!   rz   r{   r   r   r   r}      r~   zRRayTaskError._make_exceptiongroup_dual_exception_instance.<locals>.cls.__getattr__c                    r   r!   r   rf   r   r   r   rB      r   zNRayTaskError._make_exceptiongroup_dual_exception_instance.<locals>.cls.__str__)r-   r.   r/   r   r4   r   rX   r   rw   r}   rB   r9   r   r   r7   r   rv      s    

rv   r   r   r   r   r   r   r   rd      s   
z9RayTaskError._make_exceptiongroup_dual_exception_instancec              
   C   s   | j j}tt|r| S z|  W S  ty2 } ztdt| j  d|  | W  Y d}~S d}~w t	yS } ztdt| j  d|  | W  Y d}~S d}~ww )a;  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`.
        zUser exception type z in RayTaskError can't be subclassed! This exception is raised as RayTaskError only. You can use `ray_task_error.cause` to access the user exception. Failure in subclassing: Nz8Failed to combine RayTaskError with user exception type z; raising RayTaskError only. This can happen when the user exception overrides attributes like `args` or otherwise blocks subclass construction. Failure in subclassing: )
rS   r8   
issubclassrC   rg   rU   rV   warningr   r(   )r   r   rZ   r   r   r   as_instanceof_cause   s0   	

z RayTaskError.as_instanceof_causec              	   C   s  | j  d}g }d}t|D ]x\}}|drLtjj | j dtjj	 d| j
 d| j }| jr@|d| j d| j d	7 }n|d	7 }d}|| q|d
r~d|v sad|v sad|v sad|v r~d|v rj|d |d t|k r}||d  dr}d}q|rd}q|| qd|S )z"Format a RayTaskError as a string.r   Fz
Traceback z()z (pid=z, ip=z, actor_id=z, repr=r   z  File zray/worker.pyzray/_private/zray/util/tracing/zray/_raylet.pyxz&ray._raylet.raise_if_dependency_failedzJ  At least one of the input arguments for this task could not be computed:   z    T)rP   stripsplit	enumerate
startswithcoloramaForeCYANrF   RESETrK   rN   rQ   rR   appendlenr   )r   linesoutcode_from_internal_fileilinetraceback_liner   r   r   rB     sL   	

"
zRayTaskError.__str__)NNNNN)r]   rC   )
r-   r.   r/   r0   r4   rg   re   rd   r   rB   r   r   r   r   rC   f   s    

0

"$!rC   c                   @      e Zd ZdZdd ZdS )LocalRayletDiedErrorz,Indicates that the task's local raylet died.c                 C      dS )NzDThe task's local raylet died. Check raylet.out for more information.r   rf   r   r   r   rB   \  r   zLocalRayletDiedError.__str__Nr-   r.   r/   r0   rB   r   r   r   r   r   X      r   c                   @   r   )WorkerCrashedErrorzCIndicates that the worker died unexpectedly while executing a task.c                 C   s   	 dS )NzrThe worker died unexpectedly while executing this task. Check python-core-worker-*.log files for more information.r   rf   r   r   r   rB   d  s   zWorkerCrashedError.__str__Nr   r   r   r   r   r   `  r   r   c                	   @   sj   e Zd ZdZdZdeddfdedededefd	d
ZdefddZe	defddZ
e	defddZdS )RayActorErrora  Indicates that the actor has outages unexpectedly before finishing a task.

    This exception could happen because the actor process is dead, or is unavailable for
    the moment. Ray raises subclasses `ActorDiedError` and `ActorUnavailableError`
    respectively.
    z:The actor experienced an error before finishing this task.NFrY   r   actor_init_failed	preemptedc                 C   s   || _ || _|| _|| _d S r!   )rY   r   _actor_init_failed
_preempted)r   rY   r   r   r   r   r   r   r4   v  s   
zRayActorError.__init__r]   c                 C   rm   r!   r   rf   r   r   r   rB        zRayActorError.__str__c                 C   rm   r!   )r   rf   r   r   r   r     ro   zRayActorError.preemptedc                 C   rm   r!   )r   rf   r   r   r   r     ro   zRayActorError.actor_init_failed)r-   r.   r/   r0   BASE_ERROR_MSGr?   boolr4   rB   r   r   r   r   r   r   r   r   k  s*    
r   c                       sL   e Zd ZdZdZ	d
deeeef  f fddZ	e
defdd	Z  ZS )ActorDiedErrorai  Indicates that the actor died unexpectedly before finishing a task.

    This exception could happen either because the actor process dies while
    executing a task, or because a task is submitted to a dead actor.

    Args:
        cause: The cause of the actor error. `RayTaskError` type means
            the actor has died because of an exception within `__init__`.
            `ActorDiedErrorContext` means the actor has died because of
            an unexpected system error. None means the cause isn't known.
            Theoretically, this shouldn't happen,
            but it's there as a safety check.
    z7The actor died unexpectedly before finishing this task.NrS   c                    sP  d}t j}d}d}|snt|trd}|j}d|  }nt|ts%J t jg}|d|j  |dt	|j
   |jdkrM|d|j  |jd	kr[|d
|j  |jd	kri|d|j  |jd	krw|d|j  ||j |jr|d |jr|jjtjkrd}d|}t	|j
 }t |||| dS )zF
        Construct a RayActorError by building the arguments.
        NFTz@The actor died because of an error raised in its creation task, z	class_name: z	actor_id: r   z	pid: r>   z	name: z	namespace: z	ip: zAThe actor never ran - it was cancelled before it started running.r   )r   r   rb   rC   rR   rB   r	   r   
class_namer   rY   hexrK   r|   ray_namespacenode_ip_addressr<   never_startednode_death_inforeasonr   AUTOSCALER_DRAIN_PREEMPTEDr   r3   r4   )r   rS   rY   r   r   r   error_msg_linesr7   r   r   r4     sN   





zActorDiedError.__init__
task_errorc                 C   s   t | S r!   )r   )r   r   r   r   from_task_error  s   zActorDiedError.from_task_errorr!   )r-   r.   r/   r0   r   r   r   rC   r	   r4   r1   r   r9   r   r   r7   r   r     s    5r   c                       s.   e Zd ZdZdedee f fddZ  ZS )ActorUnavailableErrorzLRaised when the actor is temporarily unavailable but may be available later.r<   rY   c                    sH   |d ur
t | nd }d| d| d}d}d}t |||| d S )Nz
The actor z is unavailable: z:. The task may or may not have been executed on the actor.F)r   r   r3   r4   )r   r<   rY   r   r   r   r7   r   r   r4     s   zActorUnavailableError.__init__)	r-   r.   r/   r0   r?   r   bytesr4   r9   r   r   r7   r   r     s    "r   c                   @   "   e Zd ZdZdddZdd ZdS )RaySystemErrorzpIndicates that Ray encountered a system error.

    This exception can be thrown when the raylet is killed.
    Nc                 C   r=   r!   
client_excrP   )r   r   rP   r   r   r   r4        
zRaySystemError.__init__c                 C   s&   d| j  }| jr|d| j 7 }|S )NzSystem error: z
traceback: r   )r   r   r   r   r   rB     s   zRaySystemError.__str__r!   r-   r.   r/   r0   r4   rB   r   r   r   r   r     s    
r   c                       s4   e Zd ZdZdef fddZdefddZ  ZS )AuthenticationErrora  Indicates that an authentication error occurred.

    Most commonly, this is caused by a missing or mismatching token set on the client
    (e.g., a Ray CLI command interacting with a remote cluster).

    Only applicable when `RAY_AUTH_MODE` is not set to `disabled`.
    r   c                    s   || _ d| _t | d S )NT)r   __suppress_context__r3   r4   r   r   r7   r   r   r4   
  s   zAuthenticationError.__init__r]   c                 C   sZ   d}ddl m} ddlm}m} | }||jkr"||}d| d}d}| jd | | S )	Nr>   r   )get_authentication_mode_name)AuthenticationModeget_authentication_modez# Note: RAY_AUTH_MODE is currently 'z' (not 'token').a   Ensure that the token for the cluster is available in a local file (e.g., ~/.ray/auth_token or via RAY_AUTH_TOKEN_PATH) or as the `RAY_AUTH_TOKEN` environment variable. To generate a token for local development, use `ray get-auth-token --generate` For remote clusters, ensure that the token is propagated to all nodes of the cluster when token authentication is enabled. For more information, see: https://docs.ray.io/en/latest/ray-security/token-auth.htmlrD   )0ray._private.authentication.authentication_utilsr   ray._rayletr   r   TOKENr   )r   auth_mode_noter   r   r   current_mode	mode_name	help_textr   r   r   rB     s   

zAuthenticationError.__str__r-   r.   r/   r0   r?   r4   rB   r9   r   r   r7   r   r      s    r   c                   @      e Zd ZdZdS )UserCodeExceptiona	  Indicates that an exception occurred while executing user code.
    For example, this exception can be used to wrap user code exceptions
    from a remote task or actor. The `retry_exceptions` parameter will
    still respect the underlying cause of this exception.Nr-   r.   r/   r0   r   r   r   r   r   +  s    r   c                       r2   )ObjectStoreFullErrorzIndicates that the object store is full.

    This is raised if the attempt to store the object fails
    because the object store is full even after multiple retries.
    c                       t t|  d S )Nz
The local object store is full of objects that are still in scope and cannot be evicted. Tip: Use the `ray memory` command to list active objects in the cluster.)r3   r   rB   rf   r7   r   r   rB   =  s   zObjectStoreFullError.__str__r-   r.   r/   r0   rB   r9   r   r   r7   r   r   5      r   c                       r2   )OutOfDiskErrorzIndicates that the local disk is full.

    This is raised if the attempt to store the object fails
    because both the object store and disk are full.
    c                    r   )Nz
The object cannot be created because the local object store is full and the local disk's utilization is over capacity (95% by default).Tip: Use `df` on this node to check disk usage and `ray memory` to check object store memory usage.)r3   r   rB   rf   r7   r   r   rB   N  s   zOutOfDiskError.__str__r   r   r   r7   r   r   F  r   r   c                   @       e Zd ZdZdd Zdd ZdS )OutOfMemoryErrorzIndicates that the node is running out of memory and is close to full.

    This is raised if the node is low on memory and tasks or actors are being
    evicted to free up memory.
    c                 C   rp   r!   r   r   r   r   r   r4   c  rx   zOutOfMemoryError.__init__c                 C   rm   r!   r   rf   r   r   r   rB   f  r   zOutOfMemoryError.__str__Nr   r   r   r   r   r   Z  s    r   c                   @   r   )NodeDiedErrorz6Indicates that the node is either dead or unreachable.c                 C   rp   r!   r   r   r   r   r   r4   o  rx   zNodeDiedError.__init__c                 C   rm   r!   r   rf   r   r   r   rB   r  r   zNodeDiedError.__str__Nr   r   r   r   r   r   j  s    r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ObjectLostErrorzIndicates that the object is lost from distributed memory, due to
    node failure or system error.

    Args:
        object_ref_hex: Hex ID of the object.
    c                 C   s    || _ || _|tjd| _d S )Nz
  )object_ref_hexowner_addressreplaceray_constantsCALL_STACK_LINE_DELIMITER	call_site)r   r   r   r   r   r   r   r4     s
   
zObjectLostError.__init__c                 C   s4   d| j  d}| jr|d| j 7 }|S |d7 }|S )NzFailed to retrieve object z. zThe ObjectRef was created at: zTo see information about where this ObjectRef was created in Python, set the environment variable RAY_record_ref_creation_sites=1 during `ray start` and `ray.init()`.)r   r   r@   r   r   r   	_base_str  s   zObjectLostError._base_strc                 C      |   d d| j d S )N

zAll copies of z have been lost due to node failure. Check cluster logs (`/tmp/ray/session_latest/logs`) for more information about the failure.r   r   rf   r   r   r   rB        zObjectLostError.__str__N)r-   r.   r/   r0   r4   r   rB   r   r   r   r   r   v  s
    r   c                   @   r   )ObjectFetchTimedOutErrorzgIndicates that an object fetch timed out.

    Args:
        object_ref_hex: Hex ID of the object.
    c                 C   r   )Nr   zFetch for object z` timed out because no locations were found for the object. This may indicate a system-level bug.r   rf   r   r   r   rB     r   z ObjectFetchTimedOutError.__str__Nr   r   r   r   r   r         r   c                   @   r   )RpcErrorz0Indicates an error in the underlying RPC system.Nc                 C   r=   r!   )r   rpc_code)r   r   r   r   r   r   r4     r   zRpcError.__init__c                 C   rm   r!   r   rf   r   r   r   rB     r   zRpcError.__str__r!   r   r   r   r   r   r     s    
r   c                   @   r   )ReferenceCountingAssertionErrorzIndicates that an object has been deleted while there was still a
    reference to it.

    Args:
        object_ref_hex: Hex ID of the object.
    c                 C      |   d d S )Nr   z_The object has already been deleted by the reference counting protocol. This should not happen.r   rf   r   r   r   rB        z'ReferenceCountingAssertionError.__str__Nr   r   r   r   r   r         r   c                   @   r   )ObjectFreedErrorzIndicates that an object was manually freed by the application.

    Attributes:
        object_ref_hex: Hex ID of the object.
    c                 C   r   )Nr   zThe object was manually freed using the internal `free` call. Please ensure that `free` is only called once the object is no longer needed.r   rf   r   r   r   rB     r   zObjectFreedError.__str__Nr   r   r   r   r   r     r   r   c                   @   r   )OwnerDiedErrorzIndicates that the owner of the object has died while there is still a
    reference to the object.

    Args:
        object_ref_hex: Hex ID of the object.
    c                 C   sp   d}| j r,zt }|| j  |j}t|j}d|  d| }W n	 ty+   Y nw |  d d| d S )Nz`/tmp/ray/session_latest/logs`z`/tmp/ray/session_latest/logs/*z*` at IP address r   zThe object's owner has exited. This is the Python worker that first created the ObjectRef via `.remote()` or `ray.put()`. Check cluster logs (z7) for more information about the Python worker failure.)	r   r
   r"   
ip_addressr   	worker_idr   r(   r   )r   log_locaddrip_addrr   r   r   r   rB     s,   
zOwnerDiedError.__str__Nr   r   r   r   r   r     r   r   c                       s   e Zd ZdZejdejdejdejdej	dej
dejdejd	ejd
i	Z				ddedddedee def
 fddZdd Z  ZS )ObjectReconstructionFailedErrorz2Indicates that the object cannot be reconstructed.zThe object cannot be reconstructed because the maximum number of task retries has been exceeded. Consider increasing the number of retries using `@ray.remote(max_retries=N)`.zThe object cannot be reconstructed because its lineage has been evicted to reduce memory pressure. To prevent this error, set the environment variable RAY_max_lineage_bytes=<bytes> (default 1GB) during `ray start`.zThe object cannot be reconstructed because it was created by ray.put(), which has no task lineage. To prevent this error, return the value from a task instead.zThe object cannot be reconstructed because the task was created with max_retries=0. Consider enabling retries using `@ray.remote(max_retries=N)`.zThe object cannot be reconstructed because it crossed an ownership boundary. Only the owner of an object can trigger reconstruction, but this worker borrowed the object from another worker.z{The object cannot be reconstructed because Ray is running in local mode. Local mode does not support object reconstruction.zThe object cannot be reconstructed because its reference was not found in the reference counter. Please file an issue at https://github.com/ray-project/ray/issues.zXThe object cannot be reconstructed because the task that would produce it was cancelled.zThe object cannot be reconstructed because lineage reconstruction is disabled system-wide (object_reconstruction_enabled=False).Nr>   r   r   r   reason_messager   r   c                    s0   t  ||| || _|p| j| jd| _dS )a  Initialize ObjectReconstructionFailedError.

        Args:
            object_ref_hex: Hex string of the object reference.
            reason: ErrorType enum value indicating why reconstruction failed.
            reason_message: Human-readable explanation of the failure.
            owner_address: Address of the object's owner.
            call_site: Call site where the object was created.
        zpUnknown error reason. This should not happen, please file an issue at https://github.com/ray-project/ray/issues.N)r3   r4   r   REASON_MESSAGESgetr   )r   r   r   r   r   r   r7   r   r   r4   @  s   

z(ObjectReconstructionFailedError.__init__c                 C   s>   |   }| jr| jrt| jnd}|d| d| j  S |S )NUNKNOWNz

[z] )r   r   r   r   r6   )r   basereason_namer   r   r   rB   Y  s
   z'ObjectReconstructionFailedError.__str__)NNNr>   )r-   r.   r/   r0   r   .OBJECT_UNRECONSTRUCTABLE_MAX_ATTEMPTS_EXCEEDED(OBJECT_UNRECONSTRUCTABLE_LINEAGE_EVICTEDOBJECT_UNRECONSTRUCTABLE_PUT)OBJECT_UNRECONSTRUCTABLE_RETRIES_DISABLED!OBJECT_UNRECONSTRUCTABLE_BORROWED#OBJECT_UNRECONSTRUCTABLE_LOCAL_MODE&OBJECT_UNRECONSTRUCTABLE_REF_NOT_FOUND'OBJECT_UNRECONSTRUCTABLE_TASK_CANCELLED)OBJECT_UNRECONSTRUCTABLE_LINEAGE_DISABLEDr   r?   r   r
   r4   rB   r9   r   r   r7   r   r     sJ    1r   c                   @   r   )GetTimeoutErrorz.Indicates that a call to the worker timed out.Nr   r   r   r   r   r
  a      r
  c                   @   r   )PlasmaObjectNotAvailablezACalled when an object was not available within the given timeout.Nr   r   r   r   r   r  h  r  r  c                   @   r   )AsyncioActorExitzBRaised when an asyncio actor intentionally exits via exit_actor().Nr   r   r   r   r   r  o  r  r  c                   @   s(   e Zd ZdZddefddZdd ZdS )	RuntimeEnvSetupErrorzRaised when a runtime environment fails to be set up.

    Args:
        error_message: The error message that explains
            why runtime env setup has failed.
    Nr<   c                 C   rp   r!   r<   r   r<   r   r   r   r4     rx   zRuntimeEnvSetupError.__init__c                 C   s"   dg}| j r|| j  d|S )Nz%Failed to set up runtime environment.r   )r<   r   r   )r   msgsr   r   r   rB     s   
zRuntimeEnvSetupError.__str__r!   r-   r.   r/   r0   r?   r4   rB   r   r   r   r   r  v  s    r  c                   @   r   )TaskPlacementGroupRemoved:Raised when the corresponding placement group was removed.c                 C   r   )Nz@The placement group corresponding to this task has been removed.r   rf   r   r   r   rB     r   z!TaskPlacementGroupRemoved.__str__Nr   r   r   r   r   r    r   r  c                   @   r   )ActorPlacementGroupRemovedr  c                 C   r   )NzAThe placement group corresponding to this Actor has been removed.r   rf   r   r   r   rB     r   z"ActorPlacementGroupRemoved.__str__Nr   r   r   r   r   r    r   r  c                   @   r   )PendingCallsLimitExceededzRaised when the pending actor calls exceeds `max_pending_calls` option.

    This exception could happen probably because the caller calls the callee
    too frequently.
    Nr   r   r   r   r   r    s    r  c                   @   &   e Zd ZdZdefddZdd ZdS )TaskUnschedulableErrorzRaised when the task cannot be scheduled.

    One example is that the node specified through
    NodeAffinitySchedulingStrategy is dead.
    r<   c                 C   rp   r!   r  r  r   r   r   r4     rx   zTaskUnschedulableError.__init__c                 C      d| j  S )NzThe task is not schedulable: r  rf   r   r   r   rB     r~   zTaskUnschedulableError.__str__Nr  r   r   r   r   r        r  c                   @   r  )ActorUnschedulableErrorzRaised when the actor cannot be scheduled.

    One example is that the node specified through
    NodeAffinitySchedulingStrategy is dead.
    r<   c                 C   rp   r!   r  r  r   r   r   r4     rx   z ActorUnschedulableError.__init__c                 C   r  )NzThe actor is not schedulable: r  rf   r   r   r   rB     r~   zActorUnschedulableError.__str__Nr  r   r   r   r   r    r  r  c                   @   r   )ObjectRefStreamEndOfStreamErrorzWRaised by streaming generator tasks when there are no more ObjectRefs to
    read.
    Nr   r   r   r   r   r        r  c                   @   r   )(OufOfBandObjectRefSerializationExceptionznRaised when an `ray.ObjectRef` is out of band serialized by
    `ray.cloudpickle`. It is an anti pattern.
    Nr   r   r   r   r   r    r  r  alpha)	stabilityc                   @   r   )RayChannelErrorz[Indicates that Ray encountered a system error related
    to ray.experimental.channel.
    Nr   r   r   r   r   r!    r  r!  c                   @   r   )RayChannelTimeoutErrorz;Raised when the Compiled Graph channel operation times out.Nr   r   r   r   r   r"    r  r"  c                   @   r   )RayCgraphCapacityExceededzBRaised when the Compiled Graph channel's buffer is at max capacityNr   r   r   r   r   r#    r  r#  c                   @   r   )RayDirectTransportErrorzERaised when there is an error during a Ray direct transport transfer.Nr   r   r   r   r   r$    r  r$  c                   @   r  )r*   a  Raised when there is an error deserializing a serialized exception.

    This occurs when deserializing (unpickling) a previously serialized exception
    fails. In this case, we fall back to raising the string representation of
    the original exception along with its stack trace that was captured at the
    time of serialization.

    For more details and how to handle this with custom serializers, :ref:`configuring custom exception serializers <custom-exception-serializer>`

    Args:
        original_stack_trace: The string representation and stack trace of the
            original exception that was captured during serialization.
    original_stack_tracec                 C   rp   r!   _original_stack_trace)r   r%  r   r   r   r4     rx   z UnserializableException.__init__c                 C   r  )NzFailed to deserialize exception. Refer to https://docs.ray.io/en/latest/ray-core/objects/serialization.html#custom-serializers-for-exceptions for more information.
Original exception:
r&  rf   r   r   r   rB     s   zUnserializableException.__str__Nr  r   r   r   r   r*     s    r*   c                       .   e Zd ZdZdef fddZdd Z  ZS )ActorAlreadyExistsErrora%  Raised when a named actor already exists.

    Note that this error is not only a subclass of RayError, but also a subclass of ValueError, to maintain backward compatibility.

    Args:
        error_message: The error message that contains information about the actor name and namespace.
    r<   c                       t  | || _d S r!   r3   r4   r<   r  r7   r   r   r4        
z ActorAlreadyExistsError.__init__c                 C   rm   r!   r  rf   r   r   r   rB     r   zActorAlreadyExistsError.__str__r   r   r   r7   r   r)    s    r)  c                       r(  )ActorHandleNotFoundErrora  Raised when trying to kill an actor handle that doesn't exist.

    This typically happens when using an actor handle from a previous Ray session
    after calling ray.shutdown() and ray.init().

    Note that this error is not only a subclass of RayError, but also a subclass of ValueError,
    to maintain backward compatibility.

    Args:
        error_message: The error message that contains information about the actor handle.
    r<   c                    r*  r!   r+  r  r7   r   r   r4   -  r,  z!ActorHandleNotFoundError.__init__c                 C   rm   r!   r  rf   r   r   r   rB   1  r   z ActorHandleNotFoundError.__str__r   r   r   r7   r   r-    s    r-  )OloggingrI   r`   	tracebackr   typingr   r   r   ray._private.ray_constants_privater   ray.cloudpicklecloudpickler   r   r   r   r   ray.core.generated.common_pb2r   r	   r
   r   r   r   r   ray.util.annotationsr   r   	getLoggerr-   rV   r(   r   r+   r:   rC   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   AssertionErrorr   r   r   r   TimeoutErrorr
  r  r  r  r  r  r  r  r  r  r  r!  r"  r#  r$  r*   
ValueErrorr)  r-  RAY_EXCEPTION_TYPESr   r   r   r   <module>   s    $	
& r
&K*	(&R
