
    ɯeiaW                       d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
 ddlmZ ddlmZ ddlmZmZ dd	lmZ e	rdd
lmZ ddlmZ dd
lmZ ddlmZ  ee      Zej<                  j?                  dd      Z  ejB                  d      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$      Z0 G d) d*e$      Z1 G d+ d,e$      Z2 G d- d.e$      Z3 G d/ d0e$      Z4 G d1 d2e$      Z5 G d3 d4e$      Z6 G d5 d6e$      Z7 G d7 d8e$      Z8 G d9 d:e$      Z9 G d; d<e$      Z: G d= d>e$      Z; G d? d@e$      Z< G dA dBe$      Z= G dC dDe$      Z> G dE dFe$      Z? G dG dHe$      Z@ G dI dJe@      ZA G dK dLe$      ZBy)M    )annotationsN)	getLogger)TYPE_CHECKINGAny   )ER_HTTP_GENERAL_ERROR)SecretDetector)TelemetryDataTelemetryField)get_time_millis)SnowflakeConnection)SnowflakeCursor	snowflake	connectorz^(\d{6,})(?: \((\S+)\))?:c            
          e Zd ZdZddddddddej
                  df
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZddZe	dd       Z
ddZ	 	 dd	Z	 	 	 	 	 	 dd
Z	 	 	 	 	 	 	 	 ddZe		 	 	 	 	 	 	 	 	 	 dd       Ze		 d	 	 	 	 	 	 	 dd       Ze		 	 	 	 	 	 	 	 	 	 dd       Ze		 	 	 	 	 	 	 	 dd       Ze		 	 	 	 	 	 	 	 	 	 dd       Ze		 	 	 	 	 	 dd       Z xZS )ErrorzBase Snowflake exception class.NTc                   t         |   |       || _        || _        |xs d| _        |xs d| _        || _        || _        |	| _        |
| _	        | j                  rt        j                  |      }n	d| _        d }| j                  dk7  r:|s7| j
                  dk7  r|s%t        j                         t        j                  t        j                   fv r<| j                  dd| j
                   d| j                   d| j                   | _        n| j                  dd| j
                   d| j                   | _        n|st        j                         t        j                  t        j                   fv r/| j                  dd| j                   d| j                   | _        n!| j                  dd| j                   | _        | j#                         | _        | j                  r| j'                  |||       y y )Nn/azUnknown error06d (z): z: )super__init__msgraw_msgerrnosqlstatesfqidqueryerrtypesend_telemetryRE_FORMATTED_ERRORmatchloggergetEffectiveLevelloggingINFODEBUGgenerate_telemetry_stacktracetelemetry_tracebackexception_telemetry)selfr   r   r   r   r   done_format_msg
connectioncursorr    r!   already_formatted_msg	__class__s               \/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/snowflake/connector/errors.pyr   zError.__init__!   s    	[b
 )E

,88 %7$<$<S$A!&DH$(!::O}}%,//1gllGMM5RR&*jj%5Rc$**UWX\X`X`Wa#b&*jj%5Rc$((#T,//1gllGMM5RR&*jj%5R

|2dhhZ#P&*jj%5Rz#B $(#E#E#G $$S&*=     c                "    | j                         S N)__str__r,   s    r2   __repr__zError.__repr__Y   s    ||~r3   c                    | j                   S r5   r   r7   s    r2   r6   zError.__str__\       xxr3   c            	        t        j                         d d } t               }| D ]}  }t        |j                  v s|j                  j                  t              }|j                  t        j                  |j                  |d  |j                  |j                  d              dj                  t        j                  |            S )N )line)	tracebackextract_stacklistconnector_base_pathfilenamefindappendFrameSummarylinenonamejoinformat_list)stack_framesfiltered_framesframesafe_path_indexs       r2   r)   z#Error.generate_telemetry_stacktrace_   s     !..0"5&! 	E"enn4"'.."5"56I"J  &&**'78

		  wwy,,_=>>r3   c                    | j                   dk7  r| j                  dd| j                    dS | j                  dk7  r| j                  dS y )Nr   r   r   )r   )r   r   r7   s    r2   telemetry_msgzError.telemetry_msgv   sJ    ==E!jj%Ra88ZZ2jj%&r3   c                   t         j                  j                  t        j                  | j
                        i}| j                         }| j                  r'| j                  |t         j                  j                  <   | j                  r'| j                  |t         j                  j                  <   |r||t         j                  j                  <   | j                  r0t        | j                        |t         j                  j                  <   | j                  r'| j                  |t         j                   j                  <   |S )z,Generate the data to send through telemetry.)r   KEY_STACKTRACEvaluer	   mask_secretsr*   rR   r   	KEY_SFQIDr   KEY_SQLSTATE
KEY_REASONr   strKEY_ERROR_NUMBERr   KEY_ERROR_MESSAGE)r,   telemetry_data_dictrR   s      r2   !generate_telemetry_exception_dataz'Error.generate_telemetry_exception_data~   s    
 ))//1L1L((2G

 **,::BF** 8 8 > >?==EI]] ; ; A ABCP 9 9 ? ?@::ILTZZ ? ? E EF88JN(( @ @ F FG""r3   c                   ||j                   r|j                  j                  s| j                  j                  |t
        j                  j                  <   |j                  |t
        j                  j                  <   | j                  j                  |t
        j                  j                  <   t               }	 |j                  t        j                  |||            }t!        j"                  |      r%	 ddl}|j'                         j)                  |       yyyyy# t*        $ r t,        j/                  dd       Y yw xY w# t0        $ r t,        j/                  dd       Y yw xY w)zhSend telemetry data by in-band telemetry if it is enabled, otherwise send through out-of-band telemetry.N)	from_dict	timestampr.   r   z+Failed to schedule async telemetry logging.T)exc_infoz"Cursor failed to log to telemetry.)telemetry_enabled
_telemetry	is_closedr    rU   r   KEY_TYPEapplication
KEY_SOURCEr1   __name__KEY_EXCEPTIONr   _log_telemetryr
   from_telemetry_data_dictinspectisawaitableasyncioget_running_looprun_until_complete	Exceptionr$   debugAttributeError)r,   r.   telemetry_datatsresultro   s         r2   send_exception_telemetryzError.send_exception_telemetry   sB    ",,))33 =ALL<N<NN>22889>H>T>TN>44::;AEAXAXN>77==> "BR#22!::"0B:
 &&v.&002EEfM	 / 4 - #( % I%) % 
 " RADQRs0   ;<E 8#D    E E EE  E)(E)c                    	 | j                         }|| j                  |j                  |       y|| j                  ||       y| j                  d|       y# t        $ r t        j                  d       Y yw xY w)z?Main method to generate and send telemetry data for exceptions.Nz"Sending exception telemetry failed)r^   rx   r.   rr   r$   rs   )r,   r   r/   r.   r]   s        r2   r+   zError.exception_telemetry   s    	?"&"H"H"J!--%%' '--'
 --d4GH 	?LL=>	?s   .A A A A:9A:c           
        |j                  d      }|j                  d      } ||j                  d      |dn
t        |      |j                  d      |j                  d      |j                  d      |dn
t        |      | |      )	ae  Default error handler that raises an error.

        Args:
            connection: Connections in which the error happened.
            cursor: Cursor in which the error happened.
            error_class: Class of error that needs handling.
            error_value: A dictionary of the error details.

        Raises:
            A Snowflake error.
        r   r-   r   Nr   r   r   )r   r   r   r   r   r-   r.   r/   )getintbool)r.   r/   error_classerror_valuer   r-   s         r2   default_errorhandlerzError.default_errorhandler   s    $ (%//*;<&-$SZ __Z0//'*//'*'/T/5J!
 	
r3   c           
         t         j                  | |t        |      |j                  |j                  |j
                  dd      S )aG  Wrapper for errorhandler_wrapper, it is called with a cause instead of a dictionary.

        The dictionary is first extracted from the cause and then it's given to errorhandler_wrapper

        Args:
            connection: Connections in which the error happened.
            cursor: Cursor in which the error happened.
            cause: Error instance that we want to handle.

        Returns:
            None if no exceptions are raised by the connection's and cursor's error handlers.

        Raises:
            A Snowflake error if connection and cursor are None.
        T)r   r   r   r-   )r   errorhandler_wrappertyper   r   r   )r.   causer/   s      r2   errorhandler_wrapper_from_causez%Error.errorhandler_wrapper_from_cause   sA    * ))Kyy!NN#'		

 
	
r3   c                d    t         j                  | |||      }|st         j                  ||      y)a`  Error handler wrapper that calls the errorhandler method.

        Args:
            connection: Connections in which the error happened.
            cursor: Cursor in which the error happened.
            error_class: Class of error that needs handling.
            error_value: An optional dictionary of the error details.

        Returns:
            None if no exceptions are raised by the connection's and cursor's error handlers.

        Raises:
            A Snowflake error if connection, or cursor are None. Otherwise it gives the
            exception to the first handler in that order.
        N)r   hand_to_other_handlererrorhandler_make_exception)r.   r/   r~   r   handed_overs        r2   r   zError.errorhandler_wrapper  sC    . 11	
 33  r3   c                    t        |t              r0|j                  |j                  |j                  |j
                  d}n|j                  }t        j                  | |t        |      |      }|s|y)z@Like errorhandler_wrapper, but it takes a ready to go Exception.r   r   r   r   N)	
isinstancer   r   r   r   r   argsr   r   )r.   r/   	error_excr   r   s        r2   )errorhandler_wrapper_from_ready_exceptionz/Error.errorhandler_wrapper_from_ready_exception6  sm     i' }}"%.."	K $..K11O	
 O r3   c                   |j                  dd       | | j                  j                  ||f       |3|j                  j                  ||f       	 |j                  | |||       y| 	 | j                  | |||       yy# t        $ r |j                  | |||       Y yw xY w# t        $ r | j                  | |||       Y yw xY w)zIf possible give error to a higher error handler in connection, or cursor.

        Returns:
            Whether it error was successfully given to a handler.
        r-   FT)
setdefaultmessagesrF   errorhandlerNotImplementedError_errorhandler)r.   r/   r~   r   s       r2   r   zError.hand_to_other_handlerP  s     	0%8!&&['ABOO""K#=>S##J[Q #W''
FKU  ' S$$ZkRS ' W((V[+VWs$   B  *B#  B B #CCc                    |j                  dd       t        | t              r< | |d   |j                  d      |j                  d      |j                  d            S  | |      S )zCHelper function to errorhandler_wrapper that creates the exception.r-   Fr   r   r   r   r   )r   
issubclassr   r{   )r~   r   s     r2   r   z!Error.errorhandler_make_exceptionp  se     	0%8k5)&!oog.$4!oog.	  ;''r3   )r   
str | Noner   z
int | Noner   r   r   r   r   r   r-   zbool | Noner.   5SnowflakeConnection | AsyncSnowflakeConnection | Noner/   -SnowflakeCursor | AsyncSnowflakeCursor | Noner    r   r!   r}   returnNoner   rZ   )r   r   )r   z&dict[str, tuple[bool, str, str] | str])r.   r   ru   dict[str, Any]r   r   )r   rZ   r/   r   r.   r   r   r   )
r.   r   r/   r   r~   ztype[Error]r   zdict[str, str]r   r   r5   )r.   r   r   Error | Exceptionr/   SnowflakeCursor | Noner   r   )
r.   SnowflakeConnection | Noner/   r   r~   type[Error] | type[Exception]r   r   r   r   )r.   r   r/   r   r   r   r   r   )
r.   r   r/   r   r~   r   r   dict[str, str | bool]r   r}   )r~   r   r   r   r   r   )ri   
__module____qualname____doc__r   SQL_EXCEPTIONr   r8   r6   staticmethodr)   rR   r^   rx   r+   r   r   r   r   r   r   __classcell__r1   s   @r2   r   r      s   )  #  '+LP@D"0">">#6>6> 6> 	6>
 6> 6> %6> J6> >6>  6> 6> 
6>p ? ?,#	/#.!RI!R '!R 
	!RF?? >? J	?
 
?2 
'

 !
 $	

 

 
@  *.
'
 
 '
 
	
 
@  . &  3  $	 
 
   D .& % 
	 2 .& 3 +	
 
 > (2(*( 
( (r3   r   c                      e Zd ZdZy)_Warningz!Exception for important warnings.Nri   r   r   r    r3   r2   r   r     s    +r3   r   c                      e Zd ZdZy)InterfaceErrorz.Exception for errors related to the interface.Nr   r   r3   r2   r   r         8r3   r   c                      e Zd ZddZy)	HttpErrorc                P    t        j                  | fdt        j                  i| y )Nr    )r   r   r   HTTP_EXCEPTIONr,   kwargss     r2   r   zHttpError.__init__  s)    	
"11	
 	
r3   Nr   r   ri   r   r   r   r   r3   r2   r   r     s    
r3   r   c                      e Zd ZdZy)DatabaseErrorz-Exception for errors related to the database.Nr   r   r3   r2   r   r     s    7r3   r   c                      e Zd ZdZy)InternalErrorz.Exception for errors internal database errors.Nr   r   r3   r2   r   r     r   r3   r   c                      e Zd ZdZy)OperationalErrorz9Exception for errors related to the database's operation.Nr   r   r3   r2   r   r     s    Cr3   r   c                      e Zd ZdZy)ProgrammingErrorz(Exception for errors programming errors.Nr   r   r3   r2   r   r     s    2r3   r   c                      e Zd ZdZy)IntegrityErrorz4Exception for errors regarding relational integrity.Nr   r   r3   r2   r   r     s    >r3   r   c                      e Zd ZdZy)	DataErrorz<Exception for errors reporting problems with processed data.Nr   r   r3   r2   r   r     s    Fr3   r   c                      e Zd ZdZddZy)NotSupportedErrorzCException for errors when an unsupported database feature was used.c                    | j                   S r5   r:   r7   s    r2   rR   zNotSupportedError.telemetry_msg  r;   r3   Nr   )ri   r   r   r   rR   r   r3   r2   r   r     s
    Mr3   r   c                      e Zd ZdZddZy)RevocationCheckErrorz9Exception for errors during certificate revocation check.c                v    |j                  dd      }t        j                  | ft        j                  |d| y )Nr!   F)r    r!   )popr   r   r   OCSP_EXCEPTION)r,   r   r!   s      r2   r   zRevocationCheckError.__init__  s=    $4e<	
"11)	
 		
r3   Nr   ri   r   r   r   r   r   r3   r2   r   r     s
    C
r3   r   c                      e Zd ZdZddZy)InternalServerErrorz&Exception for 500 HTTP code for retry.c           
         t         j                  | |j                  d      xs dt        |j                  dd      z   t        j
                  |j                  d      |j                  d             y )Nr   zHTTP 500: Internal Server Errorr   r   r   r   r   r   r    r   r   r   r   r{   r   r   r   r   s     r2   r   zInternalServerError.__init__  s\    

5!F%F'&**Wa*@@"11ZZ
+**W% 	 	
r3   Nr   r   r   r3   r2   r   r     
    0
r3   r   c                      e Zd ZdZddZy)ServiceUnavailableErrorz&Exception for 503 HTTP code for retry.c           
         t         j                  | |j                  d      xs dt        |j                  dd      z   t        j
                  |j                  d      |j                  d             y )Nr   zHTTP 503: Service Unavailabler   r   r   r   r   r   r   s     r2   r   z ServiceUnavailableError.__init__  s\    

5!D%D'&**Wa*@@"11ZZ
+**W% 	 	
r3   Nr   r   r   r3   r2   r   r     r   r3   r   c                      e Zd ZdZddZy)GatewayTimeoutErrorz'Exception for 504 HTTP error for retry.c           
         t         j                  | |j                  d      xs dt        |j                  dd      z   t        j
                  |j                  d      |j                  d             y )Nr   zHTTP 504: Gateway Timeoutr   r   r   r   r   r   r   s     r2   r   zGatewayTimeoutError.__init__  \    

5!@%@'&**Wa*@@"11ZZ
+**W% 	 	
r3   Nr   r   r   r3   r2   r   r     
    1
r3   r   c                      e Zd ZdZddZy)ForbiddenErrorz'Exception for 403 HTTP error for retry.c           
         t         j                  | |j                  d      xs dt        |j                  dd      z   t        j
                  |j                  d      |j                  d             y )Nr   zHTTP 403: Forbiddenr   r   r   r   r   r   r   s     r2   r   zForbiddenError.__init__  s\    

5!:%:'&**Wa*@@"11ZZ
+**W% 	 	
r3   Nr   r   r   r3   r2   r   r     r   r3   r   c                      e Zd ZdZddZy)RequestTimeoutErrorz'Exception for 408 HTTP error for retry.c           
         t         j                  | |j                  d      xs dt        |j                  dd      z   t        j
                  |j                  d      |j                  d             y )Nr   zHTTP 408: Request Timeoutr   r   r   r   r   r   r   s     r2   r   zRequestTimeoutError.__init__  r   r3   Nr   r   r   r3   r2   r   r   	  r   r3   r   c                      e Zd ZdZddZy)
BadRequestz'Exception for 400 HTTP error for retry.c           
         t         j                  | |j                  d      xs dt        |j                  dd      z   t        j
                  |j                  d      |j                  d             y )Nr   zHTTP 400: Bad Requestr   r   r   r   r   r   r   s     r2   r   zBadRequest.__init__  \    

5!<%<'&**Wa*@@"11ZZ
+**W% 	 	
r3   Nr   r   r   r3   r2   r   r     r   r3   r   c                      e Zd ZdZddZy)BadGatewayErrorz'Exception for 502 HTTP error for retry.c           
         t         j                  | |j                  d      xs dt        |j                  dd      z   t        j
                  |j                  d      |j                  d             y )Nr   zHTTP 502: Bad Gatewayr   r   r   r   r   r   r   s     r2   r   zBadGatewayError.__init__(  r   r3   Nr   r   r   r3   r2   r   r   %  r   r3   r   c                      e Zd ZdZddZy)MethodNotAllowedz'Exception for 405 HTTP error for retry.c           
         t         j                  | |j                  d      xs dt        |j                  dd      z   t        j
                  |j                  d      |j                  d             y )Nr   zHTTP 405: Method not allowedr   r   r   r   r   r   r   s     r2   r   zMethodNotAllowed.__init__6  s\    

5!C%C'&**Wa*@@"11ZZ
+**W% 	 	
r3   Nr   r   r   r3   r2   r   r   3  r   r3   r   c                      e Zd ZdZddZy)TooManyRequestsz'Exception for 429 HTTP error for retry.c           
         t         j                  | |j                  d      xs dt        |j                  dd      z   t        j
                  |j                  d      |j                  d             y )Nr   zHTTP 429: Too Many Requestsr   r   r   r   r   r   r   s     r2   r   zTooManyRequests.__init__D  s\    

5!B%B'&**Wa*@@"11ZZ
+**W% 	 	
r3   Nr   r   r   r3   r2   r   r   A  r   r3   r   c                      e Zd ZddZy)RefreshTokenErrorc           	         t         j                  | |j                  d      xs d|j                  d      |j                  d      |j                  d             y )Nr   zToken Refresh Requiredr   r   r   r   )r   r   r{   r   s     r2   r   zRefreshTokenError.__init__P  sL    

5!=%=**W%ZZ
+**W% 	 	
r3   Nr   r   r   r3   r2   r   r   O  s    
r3   r   c                      e Zd ZdZddZy)OtherHTTPRetryableErrorz)Exception for other HTTP error for retry.c           
        |j                  dd      }t        j                  | |j                  d      xs d| t        |j                  dd      z   t        j
                  |j                  d      |j                  d      	       y )
Ncoder   r   zHTTP r   r   r   r   r   )r{   r   r   r   r   r   )r,   r   r   s      r2   r   z OtherHTTPRetryableError.__init__]  sq    zz&%(

5!3uTF^'&**Wa*@@"11ZZ
+**W% 	 	
r3   Nr   r   r   r3   r2   r   r   Z  s
    3	
r3   r   c                  $     e Zd ZdZd fdZ xZS )MissingDependencyErrorz*Exception for missing extras dependencies.c                ,    t         |   d|        y )NzMissing optional dependency: r:   )r   r   )r,   
dependencyr1   s     r2   r   zMissingDependencyError.__init__l  s    <ZLIJr3   )r   rZ   r   r   )ri   r   r   r   r   r   r   s   @r2   r   r   i  s    4K Kr3   r   c                      e Zd ZdZy)BindUploadErrorz:Exception for bulk array binding stage optimization fails.Nr   r   r3   r2   r   r   p  s    Dr3   r   c                      e Zd ZdZy)RequestExceedMaxRetryErrorz^Exception for REST call to remote storage API exceeding maximum retries with transient errors.Nr   r   r3   r2   r   r   v  s    hr3   r   c                      e Zd ZdZy)TokenExpiredErrorz]Exception for REST call to remote storage API failed because of expired authentication token.Nr   r   r3   r2   r   r   |  s    gr3   r   c                      e Zd ZdZy)PresignedUrlExpiredErrorzVException for REST call to remote storage API failed because of expired presigned URL.Nr   r   r3   r2   r  r    s    `r3   r  c                      e Zd ZdZy)ConfigSourceErrorzjConfiguration source related errors.

    Examples are environmental variable and configuration file.
    Nr   r   r3   r2   r  r        r3   r  c                      e Zd ZdZy)MissingConfigOptionErrorzWhen a configuration option is missing from the final, resolved configurations.

    This is a special-case of ConfigSourceError.
    Nr   r   r3   r2   r  r    r  r3   r  c                      e Zd ZdZy)ConfigManagerErrorzhConfiguration manager related errors.

    This means that ConfigManager is misused by a developer.
    Nr   r   r3   r2   r	  r	    r  r3   r	  )C
__future__r   rm   r&   osrer@   r   typingr   r   	errorcoder   secret_detectorr	   	telemetryr
   r   	time_utilr   aio._connectionr   AsyncSnowflakeConnectionaio._cursorr   AsyncSnowflakeCursorr.   r/   ri   r$   pathrJ   rC   compiler"   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r	  r   r3   r2   <module>r     s   "   	 	   % , + 4 &PD/'	8	ggll;<   RZZ <= a(I a(H	y 		U 	
 
	E 		M 		} 		} 		] 		 	 

+ 


% 

e 

% 

U 

% 

 

e 

u 

e 

 

e 
KU K	e 		 		 		u 	 0  r3   