
    m              	          S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSK	Jr  SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  \R8                  rSr  SS\S\S\S\ 4S jjr!S\4S jr"g)z+BQ CLI helper functions for error handling.    N)app)flags)
exceptions)bq_to_gcloud_config_classes)bq_error)bq_gcloud_utils)
bq_logging)
stringutilaz  In order to get started, please visit the Google APIs Console to create a project and agree to our Terms of Service:
	https://console.cloud.google.com/

For detailed sign-up instructions, please see our Getting Started Guide:
	https://cloud.google.com/bigquery/docs/quickstarts/quickstart-command-line

Once you have completed the sign-up process, please try your command again.errnamemessage_prefixreturnc           	      >   [         R                  " [        R                  5        [        R
                  " [        5      n[        U [        5      (       a  UR                  SU S9  U R                  $ / nSn[        R                  " 5       u  pgnSR                  [        R                  " XgU5      5      n	[!        5       n
["        R$                  " 5       n[&        R(                  " S5      U[*        R,                  " ["        R.                  5      [        R0                   Vs/ s H  n[*        R,                  " U5      PM     sn[2        R4                  " S[2        R6                  " 5       5      [*        R,                  " U	5      4-  n[8        R:                  " S[8        R<                  5        [         R>                  " U 5      n[        U [@        RB                  [@        RD                  45      (       a  URG                  SU< S	U< 35        S
nGOF[        U [@        RH                  5      (       a4  URG                  [K        U 5      S-   5        URG                  [L        5        GO[        U [@        RN                  5      (       a  URG                  SU< 35        GO[        U [@        RP                  5      (       a:  [        U [@        RR                  5      (       d  URG                  SU< S	U< 35        GOd[        U [T        RV                  [@        RX                  45      (       a  URG                  U5        GO"[        U [Z        R\                  5      (       a  URG                  U5        GO[        U [^        5      (       d  [        U [@        R`                  5      (       a  URG                  SU< 35        GO[        U [b        Rd                  5      (       a  URG                  SU< 35        GOo[        U [f        5      (       a  URG                  S5        GOG[        U [@        RR                  5      (       a  SU< S	U< S3nO[        U [h        Rj                  Rd                  5      (       a  SnO[        U [l        Rn                  5      (       a  SnSU-  nOs[        U [p        Rj                  Rr                  5      (       dH  [        U [t        Rv                  Rd                  5      (       d  [        U [x        Rz                  5      (       a  SnUS-   U
-   nSnU(       a  [b        R|                  " U5      n[        U5        [        U5        URG                  SU< S	U< 35        SR                  U5      nSnU(       a  [b        R|                  " U5      nUR                  UU S9  [        U5        U$ s  snf )z@Translate an error message into some printing and a return code.z$An error has caused the tool to exit)exc_info    a       ========================================
     == Platform ==
       %s
     == bq version ==
       %s
     == Command line ==
       %s
     == UTC timestamp ==
       %s
     == Error trace ==
     %s
     ========================================
     z%Y-%m-%d %H:%M:%SstrictzBigQuery error in z operation:    
zError in query string: zInvalid input: zError parsing command: z.Bigquery service returned an invalid reply in z.

Please make sure you are using the latest version of the bq tool and try again. If this problem persists, you may have encountered a bug in the bigquery client.aX  Authorization error. This may be a network connection problem, so please try again. If this problem persists, the credentials may be corrupt. Try deleting and re-creating your credentials. You can delete your credentials using "bq init --delete_credentials".

If this problem still occurs, you may have encountered a bug in the bigquery client.zservice accounta&  Authorization error. If you used %s credentials, the server likely returned an Unauthorized response. Verify that you are using the correct account with the correct permissions to access the service endpoint.

If this problem still occurs, you may have encountered a bug in the bigquery client.zNetwork connection problem encountered, please try again.

If this problem persists, you may have encountered a bug in the bigquery client. TzUnexpected exception in )@r	   ConfigurePythonLoggerFLAGSapiloglogging	getLogger__name__
isinstance
SystemExit	exceptioncodesysr   join	tracebackformat_exception_generate_contact_us_messagebq_utilsGetPlatformStringtextwrapdedentr
   
ensure_strVERSION_NUMBERargvtimestrftimegmtimecodecsregister_errorreplace_errorsEncodeForPrintingr   BigqueryNotFoundErrorBigqueryDuplicateErrorappendBigqueryTermsOfServiceErrorstr_BIGQUERY_TOS_MESSAGEBigqueryInvalidQueryErrorBigqueryErrorBigqueryInterfaceErrorr   
UsageErrorBigqueryTypeErrorr   !BigqueryGcloudDelegationUserErrorSyntaxErrorBigquerySchemaErrorr   ErrorKeyboardInterruptoauth2client_4_0clientgoogle_auth_exceptionsRefreshErrorhttpHTTPExceptiongoogleapiclienterrorshttplib2HttpLib2Error	text_wrapprint)r   r   r   loggerresponseretcodeetypevaluetbtracecontact_us_msgplatform_stritemerror_detailsmessagecredential_typewrap_error_messageresponse_messages                     #platform/bq/utils/bq_error_utils.pyprocess_errorr`   *   s3    ""5<<0X&&Z  
;cJ88O('||~5
''),,U2>
?%/1.++-,oo 	 
 


 7 7
83688
<84:  &8
<
--+T[[]
;



&	 0 	&"7"78((-'	H**H,K,KL  OOD'JKG#x;;<<OOCHtO$OO)*#x99::OO7<=#x--..z	8**8 8 OOD'JK#(B(BCDDOOG	'II  OOG#{##z	8''( ( OO745#u{{##OO7<=#())OOB
 #x6677 !%g/  
C)0066	7	7$  
C/<<	=	=)o$ (78  	31122c?117788c81122  s"^3G(g	'N	-OO6:GD YYx('78#c2	.G =s    V
c                      Sn  [         R                  " 5       nUR                  S5      nSU;   a+  SUS   ;   a"  U R                  SS5      R                  SS5      n U $ ! [         a     U $ f = f)	z!Generates the Contact Us message.a  Please file a bug report in our public issue tracker:
  https://issuetracker.google.com/issues/new?component=187149&template=0
Please include a brief description of the steps that led to this issue, as well as any rows that can be made public from the following information: 

coreaccountz@google.compublicinternalzFhttps://issuetracker.google.com/issues/new?component=187149&template=0z3http://b/issues/new?component=60322&template=178900)r   load_configgetreplace	Exception)rW   gcloud_configsgcloud_core_propertiess      r_   r%   r%      s    ( 	$002N+//7++3I>>%--h
CKK
R
?n 
	 
 				s   AA 
A+*A+)unknownz/You have encountered a bug in the BigQuery CLI.)#__doc__r0   http.clientrH   r   r!   r(   r-   r#   abslr   r   google.authr   rF   rJ   rL   oauth2client_4_0.clientrD   r&   gcloud_wrapperr   utilsr   r   r	   pyglibr
   r   r9   BaseExceptionr8   intr`   r%        r_   <module>ry      s    1    
      <     6  !   	  KJ	J
J J 		JZc rx   