
    i                         d Z ddlmZmZmZ ddl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)z1Custom exceptions for the DevAll workflow system.    )OptionalDictAnyNc            	       ^     e Zd ZdZd	dededeeef   f fdZdeeef   fdZdefdZ	 xZ
S )
MACExceptionz*Base exception for DevAll workflow system.message
error_codedetailsc                 ^    t         |   |       || _        |xs d| _        |xs i | _        y )NGENERIC_ERROR)super__init__r   r	   r
   )selfr   r	   r
   	__class__s       =/Users/bowang/.openclaw/workspace/ChatDev/utils/exceptions.pyr   zMACException.__init__
   s.    !$7}"    returnc                 J    | j                   | j                  | j                  dS )z9Convert exception to dictionary format for JSON response.r	   r   r
   r   r   s    r   to_dictzMACException.to_dict   s#     //||||
 	
r   c                 H    t        j                  | j                               S )z!Convert exception to JSON string.)jsondumpsr   r   s    r   to_jsonzMACException.to_json   s    zz$,,.))r   NN)__name__
__module____qualname____doc__strr   r   r   r   r   __classcell__r   s   @r   r   r      sI    4% % %d3PS8n %
c3h 
* *r   r   c            	       <     e Zd ZdZddededeeef   f fdZ xZS )ValidationErrorzRaised when validation fails.r   fieldr
   c                 T    t         |   |d|xs i        |r|| j                  d<   y y )NVALIDATION_ERRORr&   r   r   r
   )r   r   r&   r
   r   s       r   r   zValidationError.__init__    s/    "4gmD$)DLL! r   r   	r   r   r   r    r!   r   r   r   r"   r#   s   @r   r%   r%      s-    '* *C *c3h * *r   r%   c                   8     e Zd ZdZddedeeef   f fdZ xZS )SecurityErrorz(Raised when a security violation occurs.r   r
   c                 0    t         |   |d|xs i        y )NSECURITY_ERROR)r   r   )r   r   r
   r   s      r   r   zSecurityError.__init__)   s    "2GMrBr   )Nr*   r#   s   @r   r,   r,   &   s*    2C Cd38n C Cr   r,   c            	       <     e Zd ZdZddededeeef   f fdZ xZS )ConfigurationErrorz0Raised when configuration is invalid or missing.r   
config_keyr
   c                 T    t         |   |d|xs i        |r|| j                  d<   y y )NCONFIGURATION_ERRORr1   r)   )r   r   r1   r
   r   s       r   r   zConfigurationError.__init__0   s/    "7BG)3DLL& r   r   r*   r#   s   @r   r0   r0   -   s.    :4 4 4d3PS8n 4 4r   r0   c                   @     e Zd ZdZddedededeeef   f fdZ xZS )WorkflowExecutionErrorz%Raised when workflow execution fails.r   workflow_idnode_idr
   c                 v    t         |   |d|xs i        |r|| j                  d<   |r|| j                  d<   y y )NWORKFLOW_EXECUTION_ERRORr6   r7   r)   )r   r   r6   r7   r
   r   s        r   r   zWorkflowExecutionError.__init__9   s@    "<gmL*5DLL'&-DLL# r   NNNr*   r#   s   @r   r5   r5   6   s9    /. .# .s .\`adfiai\j . .r   r5   c            	       <     e Zd ZdZddededeeef   f fdZ xZS )WorkflowCancelledErrorz9Raised when a workflow execution is cancelled mid-flight.r   r6   r
   c                 T    t         |   |d|xs i        |r|| j                  d<   y y )NWORKFLOW_CANCELLEDr6   r)   )r   r   r6   r
   r   s       r   r   zWorkflowCancelledError.__init__D   s/    "62F*5DLL' r   r   r*   r#   s   @r   r<   r<   A   s.    C6 6# 6tCQTH~ 6 6r   r<   c                   @     e Zd ZdZddedededeeef   f fdZ xZS )ResourceNotFoundErrorz.Raised when a requested resource is not found.r   resource_typeresource_idr
   c                 v    t         |   |d|xs i        |r|| j                  d<   |r|| j                  d<   y y )NRESOURCE_NOT_FOUNDrA   rB   r)   r   r   rA   rB   r
   r   s        r   r   zResourceNotFoundError.__init__M   s@    "62F,9DLL)*5DLL' r   r:   r*   r#   s   @r   r@   r@   J   s9    86 6C 6S 6bfgjlogobp 6 6r   r@   c                   @     e Zd ZdZddedededeeef   f fdZ xZS )ResourceConflictErrorz9Raised when there's a conflict with an existing resource.r   rA   rB   r
   c                 v    t         |   |d|xs i        |r|| j                  d<   |r|| j                  d<   y y )NRESOURCE_CONFLICTrA   rB   r)   rE   s        r   r   zResourceConflictError.__init__X   s@    "5w}"E,9DLL)*5DLL' r   r:   r*   r#   s   @r   rG   rG   U   s9    C6 6C 6S 6bfgjlogobp 6 6r   rG   c                   @     e Zd ZdZddedededeeef   f fdZ xZ	S )TimeoutErrorz#Raised when an operation times out.r   	operationtimeout_durationr
   c                 v    t         |   |d|xs i        |r|| j                  d<   ||| j                  d<   y y )NTIMEOUT_ERRORrL   rM   r)   )r   r   rL   rM   r
   r   s        r   r   zTimeoutError.__init__c   sC    /7=bA(1DLL%'/?DLL+, (r   r:   )
r   r   r   r    r!   floatr   r   r   r"   r#   s   @r   rK   rK   `   s?    -@ @ @e @eijmorjres @ @r   rK   c                   @     e Zd ZdZddedededeeef   f fdZ xZ	S )ExternalServiceErrorz+Raised when an external service call fails.r   service_namestatus_coder
   c                 v    t         |   |d|xs i        |r|| j                  d<   ||| j                  d<   y y )NEXTERNAL_SERVICE_ERRORrS   rT   r)   )r   r   rS   rT   r
   r   s        r   r   zExternalServiceError.__init__n   sC    ":GMrJ+7DLL("*5DLL' #r   r:   )
r   r   r   r    r!   intr   r   r   r"   r#   s   @r   rR   rR   k   s9    56 63 6C 6aefiknfnao 6 6r   rR   )r    typingr   r   r   r   	Exceptionr   r%   r,   r0   r5   r<   r@   rG   rK   rR    r   r   <module>r[      s    7 & & *9 *,*l *CL C4 4.\ .6\ 66L 66L 6@< @6< 6r   