
    a
i&                    z   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d/S )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dS )SandboxClientErrorz)Base exception for sandbox client errors.N__name__
__module____qualname____doc__     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langsmith/sandbox/_exceptions.pyr   r      s        33Dr   r   c                      e Zd ZdZdS )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               
 	Dr   r   c                      e Zd ZdZdS )SandboxAuthenticationErrorz>Raised when authentication fails (invalid or missing API key).Nr   r   r   r   r   r   #   s        HHDr   r   c                      e Zd ZdZdS )SandboxConnectionErrorz3Raised when connection to the sandbox server fails.Nr   r   r   r   r   r   )   s        ==Dr   r   c                      e Zd ZdZdS )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          	Dr   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).
    Nmessagestrresource_typeOptional[str]c                X    t                                          |           || _        dS Initialize the error.Nsuper__init__r   selfr   r   	__class__s      r   r$   zResourceNotFoundError.__init__M   )    !!!*r   Nr   r   r   r   r	   r
   r   r   r$   __classcell__r'   s   @r   r   r   F   L         + + + + + + + + + + +r   r   c                  6     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).
    Nr   r   r   r   last_statusc                f    t                                          |           || _        || _        dS r    )r#   r$   r   r1   )r&   r   r   r1   r'   s       r   r$   zResourceTimeoutError.__init__[   s3     	!!!*&r   returnc                p    t                                                      }| j        r| d| j         dS |S )Return string representation.z (last_status: ))r#   __str__r1   )r&   baser'   s     r   r7   zResourceTimeoutError.__str__f   s@    ww   	?>>4+;>>>>r   NN)r   r   r   r   r1   r   r3   r   r	   r
   r   r   r$   r7   r,   r-   s   @r   r0   r0   S   sr          (,%)		' 	' 	' 	' 	' 	' 	'         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).
    Nr   r   r   r   c                X    t                                          |           || _        dS 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).
    Nr   r   r   r   c                X    t                                          |           || _        dS 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).
    Nr   r   r   r   c                X    t                                          |           || _        dS 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.
    Nr   r   fieldr   detailsOptional[list[dict]]
error_typec                x    t                                          |           || _        |pg | _        || _        dS r    )r#   r$   rG   rH   rJ   )r&   r   rG   rH   rJ   r'   s        r   r$   zValidationError.__init__   s:     	!!!
}"$r   )NNN)r   r   rG   r   rH   rI   rJ   r   r+   r-   s   @r   rF   rF      sW         "  $(,$(% % % % % % % % % % %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").
    Nr   r   
quota_typer   c                X    t                                          |           || _        dS r    )r#   r$   rN   )r&   r   rN   r'   s      r   r$   zQuotaExceededError.__init__   s&    !!!$r   r)   )r   r   rN   r   r+   r-   s   @r   rM   rM      sL         % % % % % % % % % % %r   rM   c                  6     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).
    Nr   r   r   r   rJ   c                f    t                                          |           || _        || _        dS r    )r#   r$   r   rJ   )r&   r   r   rJ   r'   s       r   r$   zResourceCreationError.__init__   s0     	!!!*$r   r3   c                    | j         r+t                                                       d| j          dS t                                                      S r5   z []rJ   r#   r7   r&   r'   s    r   r7   zResourceCreationError.__str__   H    ? 	>ggoo''==4?====ww   r   r9   )r   r   r   r   rJ   r   r:   r;   r-   s   @r   rQ   rQ      sr          (,$(		% 	% 	% 	% 	% 	% 	%! ! ! ! ! ! ! ! ! !r   rQ   c                      e Zd ZdZdS )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   rZ   rZ      r   r   rZ   c                      e Zd ZdZdS )SandboxNotReadyErrorzDRaised when attempting to interact with a sandbox that is not ready.Nr   r   r   r   r\   r\      s        NNDr   r\   c                  6     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.
    Nr   r   	operationr   rJ   c                f    t                                          |           || _        || _        dS r    )r#   r$   r_   rJ   )r&   r   r_   rJ   r'   s       r   r$   zSandboxOperationError.__init__  s/     	!!!"$r   r3   c                    | j         r+t                                                       d| j          dS t                                                      S rT   rV   rW   s    r   r7   zSandboxOperationError.__str__  rX   r   r9   )r   r   r_   r   rJ   r   r:   r;   r-   s   @r   r^   r^      sr          $($(		% 	% 	% 	% 	% 	% 	%! ! ! ! ! ! ! ! ! !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.
    Nr   r   timeoutOptional[int]c                ^    t                                          |dd           || _        dS )r!   commandCommandTimeout)r_   rJ   N)r#   r$   rd   )r&   r   rd   r'   s      r   r$   zCommandTimeoutError.__init__  s.    IBRSSSr   r)   )r   r   rd   re   r+   r-   s   @r   rc   rc     sL                   r   rc   c                      e Zd ZdZdS )TunnelErrorz%Base exception for TCP tunnel errors.Nr   r   r   r   rj   rj   &  s        //Dr   rj   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.
    r   r   portintc               X    t                                          |           || _        dS r    r#   r$   rm   r&   r   rm   r'   s      r   r$   z"TunnelPortNotAllowedError.__init__3  &    !!!			r   r   r   rm   rn   r+   r-   s   @r   rl   rl   ,  G                  r   rl   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.
    r   r   rm   rn   c               X    t                                          |           || _        dS r    rp   rq   s      r   r$   z%TunnelConnectionRefusedError.__init__@  rr   r   rs   r+   r-   s   @r   rv   rv   9  rt   r   rv   c                      e Zd ZdZdS )TunnelUnsupportedVersionErrorzCProtocol version mismatch between the tunnel client and the daemon.Nr   r   r   r   ry   ry   F  s        MMDr   ry   N)r   
__future__r   typingr   langsmith.utilsr   r   r   r   r   r   r   r0   r=   r@   rC   rF   rM   rQ   rZ   r\   r^   rc   rj   rl   rv   ry   r   r   r   <module>r}      s    # " " " " "       * * * * * *	 	 	 	 	 	 	 		 	 	 	 	( 	 	 		 	 	 	 	!3 	 	 		 	 	 	 	/ 	 	 		 	 	 	 	5 	 	 	.
+ 
+ 
+ 
+ 
+. 
+ 
+ 
+    -   6
+ 
+ 
+ 
+ 
++ 
+ 
+ 
+
+ 
+ 
+ 
+ 
+!3 
+ 
+ 
+
+ 
+ 
+ 
+ 
+ 2 
+ 
+ 
+$% % % % %( % % %:% % % % %+ % % %(! ! ! ! !. ! ! !@	 	 	 	 	"4 	 	 		 	 	 	 	- 	 	 	! ! ! ! !. ! ! !4
 
 
 
 
/ 
 
 
$	 	 	 	 	$ 	 	 	
 
 
 
 
 
 
 

 
 
 
 
; 
 
 
	 	 	 	 	K 	 	 	 	 	r   