
                            d Z ddlZddlmZmZmZ ddlZddlmZ 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      Z G d  d!e      Z G d" d#e      Z	 	 d+d$eeef   d%eeef   d&eeeef      d'ee   d(ee   d)efd*Zy),z0Utility functions and classes for BQ CLI errors.    N)DictListOptional)
bq_logginga  BQ CLI no longer supports the deprecated P12 format by default. To migrate to the new JSON service account key format, follow the steps in https://cloud.google.com/iam/docs/keys-create-delete#creating. To force BQ CLI to recognize P12 keys, re-run the command with --nouse_google_auth.c                       e Zd ZdZy)BigqueryErrorz$Class to represent a BigQuery error.N__name__
__module____qualname____doc__     platform/bq/utils/bq_error.pyr   r          ,r   r   c                       e Zd ZdZy)BigqueryTypeErrorz7A BQ CLI type error that should not show a stack trace.Nr	   r   r   r   r   r      s    ?r   r   c                       e Zd ZdZy)BigqueryCommunicationErrorz$Error communicating with the server.Nr	   r   r   r   r   r      r   r   r   c                       e Zd ZdZy)BigqueryInterfaceErrorz-Response from server missing required fields.Nr	   r   r   r   r   r       s    5r   r   c            
       ^     e Zd ZdZ	 ddedeeef   deeeef      dee   f fdZd Z	 xZ
S )	BigqueryServiceErrorzrBase class of Bigquery-specific error responses.

  The BigQuery server received request and returned an error.
  messageerror
error_listjob_refc                 V    t        |   |g|i | || _        || _        || _        y)a  Initializes a BigqueryServiceError.

    Args:
      message: A user-facing error message.
      error: The error dictionary, code may inspect the 'reason' key.
      error_list: A list of additional entries, for example a load job may
        contain multiple errors here for each error encountered during
        processing.
      job_ref: Optional JobReference string, if this error was encountered while
        processing a job.
    N)super__init__r   r   r   )selfr   r   r   r   argskwds	__class__s          r   r    zBigqueryServiceError.__init__*   s1    , 
GW,t,t,DJ DODLr   c                     | j                   j                  d| j                  d| j                  d| j                  S )Nz: error=z, error_list=z
, job_ref=)r$   r
   r   r   r   )r!   s    r   __repr__zBigqueryServiceError.__repr__E   s.    

	 r   )N)r
   r   r   r   strr   r   r   r    r&   __classcell__)r$   s   @r   r   r   $   sV      $ #s(^ tCH~&	
 }6r   r   c                       e Zd ZdZy)BigqueryNotFoundErrorz3The requested resource or identifier was not found.Nr	   r   r   r   r*   r*   N       ;r   r*   c                       e Zd ZdZy)BigqueryDuplicateErrorz4The requested resource or identifier already exists.Nr	   r   r   r   r-   r-   R   s    <r   r-   c                       e Zd ZdZy)BigqueryAccessDeniedErrorz8The user does not have access to the requested resource.Nr	   r   r   r   r/   r/   V   s    @r   r/   c                       e Zd ZdZy)BigqueryInvalidQueryErrorzThe SQL statement is invalid.Nr	   r   r   r   r1   r1   Z   s    %r   r1   c                       e Zd ZdZy)BigqueryTermsOfServiceErrorzUser has not ACK'd ToS.Nr	   r   r   r   r3   r3   ^   s    r   r3   c                       e Zd ZdZy)BigqueryBackendErrorzGA backend error typically corresponding to retriable HTTP 5xx failures.Nr	   r   r   r   r5   r5   b   s    Or   r5   c                       e Zd ZdZy)BigqueryClientErrorzInvalid use of BigqueryClient.Nr	   r   r   r   r7   r7   f   s    &r   r7   c                       e Zd ZdZy) BigqueryClientConfigurationErrorz(Invalid configuration of BigqueryClient.Nr	   r   r   r   r9   r9   j       0r   r9   c                       e Zd ZdZy)BigquerySchemaErrorz(Error in locating or parsing the schema.Nr	   r   r   r   r<   r<   n   r:   r   r<   c                       e Zd ZdZy)BigqueryTableConstraintsErrorz3Error in locating or parsing the table constraints.Nr	   r   r   r   r>   r>   r   r+   r   r>   r   server_errorerror_lsr   
session_idreturnc                 P   | j                  d      }|rd| d| j                  d       }n| j                  dd      }|D cg c]
  }|| k7  s	| }}|r|dz  }d}	|D cg c]=  }dj                  t        d	|j                  d
      |j                  d      g            ? }
}|	r|dj                  d |
D              z  }ndj                  |
      }|r|d|z   z  }|r|d|z  z  }t        j                  |      }|r|st        dt        |            S |dk(  rt        || ||      S |dk(  rt        || ||      S |dk(  rt        || ||      S |dk(  rt        || ||      S |dk(  rt        || ||      S |dk(  rt        || ||      S t        || ||      S c c}w c c}w )al  Returns a BigqueryError for json error embedded in server_error.

  If error_ls contains any errors other than the given one, those
  are also included in the returned message.

  Args:
    error: The primary error to convert.
    server_error: The error returned by the server. (This is only used in the
      case that error is malformed.)
    error_ls: Additional errors to include in the error message.
    job_ref: String representation a JobReference, if this is an error
      associated with a job.
    session_id: Id of the session if the job is part of one.

  Returns:
    BigqueryError representing error.
  reasonzError processing job 'z': r    z
Failure details:
Tz: Nlocation
c              3   L   K   | ]  }t        j                  |d d        yw)z - z   )initial_indentsubsequent_indentN)textwrapfill).0msgs     r   	<genexpr>z&CreateBigqueryError.<locals>.<genexpr>   s(      %C 	c%5II%s   "$z- z
In session: %szEError reported by server with missing error fields. Server returned: notFound)r   	duplicateaccessDeniedinvalidQuerytermsOfServiceNotAcceptedbackendError)getjoinfilterr   EncodeForPrintingr   r'   r*   r-   r/   r1   r3   r5   r   )r   r?   r@   r   rA   rD   r   err
new_errorswrap_error_messagenew_error_messageserror_messages               r   CreateBigqueryErrorr_   v   s   0 99X&&wis599Y3G2HIGii	2&G'8x3%<x*8%%G # iitcggj137793EFGH   tyy %  G
 II01M%%g!J..G ((1'	w!!$\!2	5  z %7KK{!'5(GLL~$WeXwOO~$WeXwOO**&'  ~'JJ	guh	HH_ 9s   
FF AF#)NN)r   rK   typingr   r   r   bq_flagsutilsr   P12_DEPRECATION_MESSAGE	Exceptionr   r   r   r   r   r*   r-   r/   r1   r3   r5   r7   r9   r<   r>   r'   r_   r   r   r   <module>re      s]   6  ' '   -I -@ @- -6] 6'= 'T<0 <=1 =A 4 A& 4 & ";  P/ P'- '1': 11- 1<$7 < " $MIS>MIsCx.MI 4S>"MI c]	MI
 MI MIr   