
    Zǻi&                       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 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/)0zCustom 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__     [/opt/lhia/marcimex/agent/venv/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y)SandboxServerReloadErroruW  Raised when the server sends a 1001 Going Away close frame.

    This indicates a server hot-reload, not a true connection failure.
    The command is still running on the server.

    This is a subclass of SandboxConnectionError, so the auto-reconnect
    logic in CommandHandle catches it along with all other
    connection errors. The distinction matters for retry strategy:
    SandboxServerReloadError triggers immediate reconnect (no backoff),
    while other SandboxConnectionError triggers exponential backoff.

    Users typically never see this exception — it's handled internally.
    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Initialize the error.Nsuper__init__resource_typeselfmessager!   	__class__s      r   r    zResourceNotFoundError.__init__M       !*r   Nr$   strr!   Optional[str]r	   r
   r   r   r    __classcell__r%   s   @r   r   r   F       + +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!   r2   r%   s       r   r    zResourceTimeoutError.__init__[   s"     	!*&r   c                `    t         |          }| j                  r| d| j                   dS |S )Return string representation.z (last_status: ))r   __str__r2   )r#   baser%   s     r   r6   zResourceTimeoutError.__str__f   s7    w V?4+;+;*<A>>r   NN)r$   r)   r!   r*   r2   r*   returnr)   r	   r
   r   r   r    r6   r,   r-   s   @r   r0   r0   S   s;     (,%)		'	' %	' #		' r   r0   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__u   r&   r   r'   r(   r+   r-   s   @r   r=   r=   n   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__   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 )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   rC   rC      r.   r   rC   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$   rH   rI   rJ   r%   s        r   r    zValidationError.__init__   s+     	!
}"$r   )NNN)r$   r)   rH   r*   rI   zOptional[list[dict]]rJ   r*   r+   r-   s   @r   rF   rF      sC    "  $(,$(%% % &	%
 "% %r   rF   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$   rN   r%   s      r   r    zQuotaExceededError.__init__   s    !$r   r'   )r$   r)   rN   r*   r+   r-   s   @r   rL   rL      s    % %r   rL   c                  @     e Zd ZdZ	 	 d	 	 	 	 	 d fdZd fdZ xZS )ResourceCreationErrora  Raised when resource provisioning fails.

    Attributes:
        resource_type: Type of resource (sandbox, volume, pool).
        error_type: Machine-readable error type (ImagePull, CrashLoop,
            SandboxConfig, Unschedulable, VolumeProvisioning).
    c                @    t         |   |       || _        || _        yr   )r   r    r!   rJ   )r#   r$   r!   rJ   r%   s       r   r    zResourceCreationError.__init__   s!     	!*$r   c                t    | j                   rt        | 	          d| j                    dS t        | 	         S r4   z []rJ   r   r6   r#   r%   s    r   r6   zResourceCreationError.__str__   7    ??go'(4??*;1==w  r   r8   )r$   r)   r!   r*   rJ   r*   r9   r;   r-   s   @r   rP   rP      s;     (,$(		%	% %	% "		%! !r   rP   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   rY   rY      r   r   rY   c                      e Zd ZdZy)SandboxNotReadyErrorzDRaised when attempting to interact with a sandbox that is not ready.Nr   r   r   r   r[   r[      s    Nr   r[   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    	operationrJ   )r#   r$   r_   rJ   r%   s       r   r    zSandboxOperationError.__init__  s      	!"$r   c                t    | j                   rt        | 	          d| j                    dS t        | 	         S rS   rU   rV   s    r   r6   zSandboxOperationError.__str__  rW   r   r8   )r$   r)   r_   r*   rJ   r*   r9   r;   r-   s   @r   r]   r]      s;     $($(		%	% !	% "		%! !r   r]   c                  &     e Zd ZdZdd fdZ xZS )CommandTimeoutErrorzRaised when a command exceeds its timeout.

    Attributes:
        timeout: The timeout value in seconds that was exceeded.
    c                8    t         |   |dd       || _        y)r   commandCommandTimeout)r_   rJ   N)r   r    timeout)r#   r$   rf   r%   s      r   r    zCommandTimeoutError.__init__  s    IBRSr   r'   )r$   r)   rf   zOptional[int]r+   r-   s   @r   rb   rb     s     r   rb   c                      e Zd ZdZy)TunnelErrorz%Base exception for TCP tunnel errors.Nr   r   r   r   rh   rh   &  s    /r   rh   c                  $     e Zd ZdZd fdZ xZS )TunnelPortNotAllowedErrorzlThe daemon rejected the port as not allowed.

    Attributes:
        port: The port that was rejected.
    c               2    t         |   |       || _        yr   r   r    portr#   r$   rm   r%   s      r   r    z"TunnelPortNotAllowedError.__init__3      !	r   r$   r)   rm   intr+   r-   s   @r   rj   rj   ,       r   rj   c                  $     e Zd ZdZd fdZ xZS )TunnelConnectionRefusedErrorzNothing is listening on the target port inside the sandbox.

    Attributes:
        port: The port that could not be reached.
    c               2    t         |   |       || _        yr   rl   rn   s      r   r    z%TunnelConnectionRefusedError.__init__@  ro   r   rp   r+   r-   s   @r   rt   rt   9  rr   r   rt   c                      e Zd ZdZy)TunnelUnsupportedVersionErrorzCProtocol version mismatch between the tunnel client and the daemon.Nr   r   r   r   rw   rw   F  s    Mr   rw   N)r   
__future__r   typingr   langsmith.utilsr   r   r   r   r   r   r   r0   r=   r@   rC   rF   rL   rP   rY   r[   r]   rb   rh   rj   rt   rw   r   r   r   <module>r{      s#   #  *	 		( 		!3 		/ 		5 	.
+. 
+- 6
++ 
+
+!3 
+
+ 2 
+$%( %:%+ %(!. !@	"4 		- 	!. !4
/ 
$	$ 	
 

; 
	K 	r   