
    bi                    v   d Z ddlmZ ddlmZ ddlmZ  G d de      Z G d de      Z G d	 d
e      Z	 G d de      Z
 G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Zy#)$zCustom exceptions for the sandbox client.

All sandbox exceptions extend LangSmithError for unified error handling.
The exceptions are organized by error type rather than resource type,
with a resource_type attribute for specific handling when needed.
    )annotations)Optional)LangSmithErrorc                      e Zd ZdZy)SandboxClientErrorz)Base exception for sandbox client errors.N__name__
__module____qualname____doc__     g/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/langsmith/sandbox/_exceptions.pyr   r      s    3r   r   c                      e Zd ZdZy)SandboxAPIErrorzvRaised when the API endpoint returns an unexpected error.

    For example, this is raised for wrong URL or path.
    Nr   r   r   r   r   r          
 	r   r   c                      e Zd ZdZy)SandboxAuthenticationErrorz>Raised when authentication fails (invalid or missing API key).Nr   r   r   r   r   r   #   s    Hr   r   c                      e Zd ZdZy)SandboxConnectionErrorz3Raised when connection to the sandbox server fails.Nr   r   r   r   r   r   )   s    =r   r   c                  &     e Zd ZdZdd fdZ xZS )ResourceNotFoundErrorzRaised when a resource is not found.

    Attributes:
        resource_type: Type of resource (sandbox, template, volume, pool, file).
    c                2    t         |   |       || _        yzInitialize the error.Nsuper__init__resource_typeselfmessager   	__class__s      r   r   zResourceNotFoundError.__init__;       !*r   Nr!   strr   Optional[str]r	   r
   r   r   r   __classcell__r"   s   @r   r   r   4       + +r   r   c                  @     e Zd ZdZ	 	 d	 	 	 	 	 d fdZd fdZ xZS )ResourceTimeoutErrorzRaised when an operation times out.

    Attributes:
        resource_type: Type of resource (sandbox, volume, pool).
        last_status: The last known status before timeout (for sandboxes).
    c                @    t         |   |       || _        || _        yr   )r   r   r   last_status)r    r!   r   r/   r"   s       r   r   zResourceTimeoutError.__init__I   s"     	!*&r   c                `    t         |          }| j                  r| d| j                   dS |S )Return string representation.z (last_status: ))r   __str__r/   )r    baser"   s     r   r3   zResourceTimeoutError.__str__T   s7    w V?4+;+;*<A>>r   NN)r!   r&   r   r'   r/   r'   returnr&   r	   r
   r   r   r   r3   r)   r*   s   @r   r-   r-   A   s;     (,%)		'	' %	' #		' r   r-   c                  &     e Zd ZdZdd fdZ xZS )ResourceInUseErrorzRaised when deleting a resource that is still in use.

    Attributes:
        resource_type: Type of resource (template, volume).
    c                2    t         |   |       || _        yr   r   r   s      r   r   zResourceInUseError.__init__c   r#   r   r$   r%   r(   r*   s   @r   r:   r:   \   r+   r   r:   c                  &     e Zd ZdZdd fdZ xZS )ResourceAlreadyExistsErrorzRaised when creating a resource that already exists.

    Attributes:
        resource_type: Type of resource (e.g., pool).
    c                2    t         |   |       || _        yr   r   r   s      r   r   z#ResourceAlreadyExistsError.__init__p   r#   r   r$   r%   r(   r*   s   @r   r=   r=   i   r+   r   r=   c                  &     e Zd ZdZdd fdZ xZS )ResourceNameConflictErrorzRaised when updating a resource name to one that already exists.

    Attributes:
        resource_type: Type of resource (volume, template, pool, sandbox).
    c                2    t         |   |       || _        yr   r   r   s      r   r   z"ResourceNameConflictError.__init__}   r#   r   r$   r%   r(   r*   s   @r   r@   r@   v   r+   r   r@   c                  :     e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 d fdZ xZS )ValidationErrora  Raised when request validation fails.

    This includes:
    - Resource values exceeding server-defined limits (CPU, memory, storage)
    - Invalid resource units
    - Invalid name formats
    - Pool validation failures (e.g., template has volumes)

    Attributes:
        field: The field that failed validation (e.g., "cpu", "memory").
        details: List of validation error details from the API.
        error_type: Machine-readable error type from the API.
    c                V    t         |   |       || _        |xs g | _        || _        yr   )r   r   fielddetails
error_type)r    r!   rE   rF   rG   r"   s        r   r   zValidationError.__init__   s+     	!
}"$r   )NNN)r!   r&   rE   r'   rF   zOptional[list[dict]]rG   r'   r(   r*   s   @r   rC   rC      sC    "  $(,$(%% % &	%
 "% %r   rC   c                  &     e Zd ZdZdd fdZ xZS )QuotaExceededErrorzRaised when organization quota limits are exceeded.

    Users should contact support@langchain.dev to increase quotas.

    Attributes:
        quota_type: Type of quota exceeded (e.g., "sandbox_count", "cpu").
    c                2    t         |   |       || _        yr   )r   r   
quota_type)r    r!   rK   r"   s      r   r   zQuotaExceededError.__init__       !$r   r$   )r!   r&   rK   r'   r(   r*   s   @r   rI   rI      s    % %r   rI   c                  2     e Zd ZdZdd fdZd fdZ xZS )SandboxCreationErrorzRaised when sandbox creation fails.

    Attributes:
        error_type: Machine-readable error type (ImagePull, CrashLoop,
            SandboxConfig, Unschedulable).
    c                2    t         |   |       || _        yr   )r   r   rG   )r    r!   rG   r"   s      r   r   zSandboxCreationError.__init__   rL   r   c                t    | j                   rt        | 	          d| j                    dS t        | 	         S r1   z []rG   r   r3   r    r"   s    r   r3   zSandboxCreationError.__str__   7    ??go'(4??*;1==w  r   r$   )r!   r&   rG   r'   r6   r8   r*   s   @r   rN   rN      s    %
! !r   rN   c                      e Zd ZdZy)DataplaneNotConfiguredErrorzRaised when dataplane_url is not available for the sandbox.

    This occurs when the sandbox-router URL is not configured for the cluster.
    Nr   r   r   r   rW   rW      r   r   rW   c                      e Zd ZdZy)SandboxNotReadyErrorzDRaised when attempting to interact with a sandbox that is not ready.Nr   r   r   r   rY   rY      s    Nr   rY   c                  @     e Zd ZdZ	 	 d	 	 	 	 	 d fdZd fdZ xZS )SandboxOperationErrorzRaised when a sandbox operation fails (run, read, write).

    Attributes:
        operation: The operation that failed (command, read, write).
        error_type: Machine-readable error type from the API.
    c                @    t         |   |       || _        || _        yr   )r   r   	operationrG   )r    r!   r]   rG   r"   s       r   r   zSandboxOperationError.__init__   s      	!"$r   c                t    | j                   rt        | 	          d| j                    dS t        | 	         S rQ   rS   rT   s    r   r3   zSandboxOperationError.__str__   rU   r   r5   )r!   r&   r]   r'   rG   r'   r6   r8   r*   s   @r   r[   r[      s;     $($(		%	% !	% "		%! !r   r[   N)r   
__future__r   typingr   langsmith.utilsr   r   r   r   r   r   r-   r:   r=   r@   rC   rI   rN   rW   rY   r[   r   r   r   <module>rb      s    #  *	 		( 		!3 		/ 	
+. 
+- 6
++ 
+
+!3 
+
+ 2 
+$%( %:%+ %(!- !2	"4 		- 	!. !r   