o
    `۷i                     @   s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ eddG dd	 d	e	Z
eddG d
d de
ZeddG dd de
ZeddG dd de
eZeddG dd de
ZdS )    )OptionalN)TaskCancelledError)DeploymentID)	PublicAPIstable)	stabilityc                   @   s   e Zd ZdS )RayServeExceptionN)__name__
__module____qualname__ r   r   J/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/serve/exceptions.pyr   
   s    r   c                       s   e Zd ZdZ		ddedeej dee f fddZ	e
defd	d
Ze
deej fddZe
dee fddZdefddZ  ZS )gRPCStatusErrora  Internal exception that wraps an exception with user-set gRPC status code.

    This is used to preserve user-set gRPC status codes when exceptions are raised
    in deployments. When a user sets a status code on the gRPC context before raising
    an exception, this wrapper carries that status code through the error handling
    path so the proxy can return the user's intended status code instead of INTERNAL.
    Noriginal_exceptioncodedetailsc                    s&   || _ || _|| _t t| d S N)_original_exception
_grpc_code_grpc_detailssuper__init__str)selfr   r   r   	__class__r   r   r      s   zgRPCStatusError.__init__returnc                 C      | j S )z'The original exception that was raised.)r   r   r   r   r   r   &      z"gRPCStatusError.original_exceptionc                 C   r   )z&The user-set gRPC status code, if any.)r   r   r   r   r   	grpc_code+   r   zgRPCStatusError.grpc_codec                 C   r   )z)The user-set gRPC status details, if any.)r   r   r   r   r   grpc_details0   r   zgRPCStatusError.grpc_detailsc                 C   s
   t | jS r   )r   r   r   r   r   r   __str__5      
zgRPCStatusError.__str__)NN)r	   r
   r   __doc__BaseExceptionr   grpc
StatusCoder   r   propertyr   r    r!   r"   __classcell__r   r   r   r   r      s$    r   alphac                       sJ   e Zd ZdZdedef fddZdefddZedefd	d
Z	  Z
S )BackPressureErrorzBRaised when max_queued_requests is exceeded on a DeploymentHandle.num_queued_requestsmax_queued_requestsc                    s&   t  || d| d| d| _d S )Nz9Request dropped due to backpressure (num_queued_requests=z, max_queued_requests=z).)r   r   _message)r   r,   r-   r   r   r   r   =   s   zBackPressureError.__init__r   c                 C   r   r   r.   r   r   r   r   r"   E   s   zBackPressureError.__str__c                 C   r   r   r/   r   r   r   r   messageH   s   zBackPressureError.message)r	   r
   r   r$   intr   r   r"   r(   r0   r)   r   r   r   r   r+   9   s    r+   c                   @   s,   e Zd ZdZddee fddZdd ZdS )	RequestCancelledErrorz(Raise when a Serve request is cancelled.N
request_idc                 C   
   || _ d S r   _request_id)r   r3   r   r   r   r   Q   r#   zRequestCancelledError.__init__c                 C   s   | j r
d| j  dS dS )NzRequest z was cancelled.zRequest was cancelled.r5   r   r   r   r   r"   T   s   zRequestCancelledError.__str__r   )r	   r
   r   r$   r   r   r   r"   r   r   r   r   r2   M   s    r2   c                   @   s0   e Zd ZdZdefddZedefddZdS )	DeploymentUnavailableErrorzRaised when a Serve deployment is unavailable to receive requests.

    Currently this happens because the deployment failed to deploy.
    deployment_idc                 C   r4   r   _deployment_id)r   r8   r   r   r   r   b   r#   z#DeploymentUnavailableError.__init__r   c                 C   s   | j  dS )Nz, is unavailable because it failed to deploy.r9   r   r   r   r   r0   e   s   z"DeploymentUnavailableError.messageN)	r	   r
   r   r$   r   r   r(   r   r0   r   r   r   r   r7   [   s
    r7   )typingr   r&   ray.exceptionsr   ray.serve._private.commonr   ray.util.annotationsr   	Exceptionr   r   r+   r2   r7   r   r   r   r   <module>   s    )