Ë
    ÂXÕ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/)0züCustom 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__© ó    úi/root/rosshost/parking-map/parking-api/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 )ÚResourceNotFoundErrorz‹Raised 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 )ÚResourceTimeoutErrorzÅRaised 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 )ÚResourceInUseErrorz‡Raised 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 )ÚResourceAlreadyExistsErrorz€Raised 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 )ÚResourceNameConflictErrorz¡Raised 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 )ÚQuotaExceededErrorzØRaised 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   ø€ à�?Š?Ü‘g‘oÓ'Ð(¨¨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)ÚDataplaneNotConfiguredErrorz�Raised 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 )ÚSandboxOperationErrorzÒRaised 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 )ÚCommandTimeoutErrorz�Raised 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   ø€ ä‰Ñ˜¨IÐBRÐÔ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 )ÚTunnelConnectionRefusedErrorzƒNothing 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   