
                             S 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  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  SSKJr  S rS rSrSrSrSrSrSS jr S r!S r"S r#g)zError Reporting Handler.    N)
exceptions)util)apis)command_loading)error_reporting_util)config)log)metrics)
properties)console_attr)	platformsc                 x    [        U [        R                  5      =(       a    [        U R                  [        5      $ )zDetermines if the error may be from installation corruption.

Args:
  err: Exception err.

Returns:
  bool, True if installation error, False otherwise
)
isinstancer   CommandLoadFailureroot_exceptionImportError)errs    0lib/googlecloudsdk/command_lib/crash_handling.py_IsInstallationCorruptionr   $   s.     S/<<
= 6
S''
57    c           
          [         R                  " SR                  U R                  U[        R
                  [        R                  R                  S   [        R                  R                  S   S95        g)zdPrompts installation error action.

Args:
  err: Exception err.
  err_string: Exception err string.
a  gcloud failed to load ({command}): {err_str}

This usually indicates corruption in your gcloud installation or problems with your Python interpreter.

Please verify that the following is the path to a working Python {py_major_version}.{py_minor_version}+ executable:
    {executable}
If it is not, please set the CLOUDSDK_PYTHON environment variable to point to a working Python {py_major_version}.{py_minor_version}+ executable.

If you are still experiencing problems, please run the following command to reinstall:
    $ gcloud components reinstall

If that command fails, please reinstall the Google Cloud CLI using the instructions here:
    https://cloud.google.com/sdk/r      )commanderr_str
executablepy_major_versionpy_minor_versionN)	r	   errorformatr   sysr   r   PythonVersionMIN_SUPPORTED_PY3_VERSIONr   
err_strings     r   _PrintInstallationActionr%   1   s_     ))
6 	++^^$22LLQO$22LLQO 	 	r   zcloud-sdk-user-errors'AIzaSyCUuWyME_r4XylltWNeydEjKSkgXkvpVyUgcloudzcloud-sdk-crashesz'AIzaSyAp4DSI_Z3-mK-B8U0t7GE34n74OWDJmakc                     [         R                  " [        R                  [        R                  5      nU" SS9nU (       a  UR                  S[        5        U$ UR                  S[        5        U$ )zReturns a client that uses an API key for Cloud SDK crash reports.

Args:
   is_crash: bool, True use CRASH_REPORTING_PARAM, if False use
   ERROR_REPORTING_PARAM.

Returns:
  An error reporting client that uses an API key for Cloud SDK crash reports.
F)get_credentialskey)	core_apisGetClientClassr   API_NAMEAPI_VERSIONAddGlobalParamCRASH_REPORTING_PARAMERROR_REPORTING_PARAM)is_crashclient_classclient_instances      r   _GetReportingClientr5   \   s_     ))$--9I9IJ, 7/""5*?@ 
 ""5*?@	r   c           	         [         R                  " 5       (       a7  [         R                  R                  R                  R                  5       (       a  g[        R                  " 5       n[        R                  " U5      n[         R                  R                  R                  R                  5       n[        R                  " 5       n[        U 5      n[        R                   " U5      n UR"                  R%                  S5      nUR'                  U[(        [*        R,                  U (       a  [.        O[0        X#S9nUR"                  R3                  Xg5      n[        R4                  " UR6                  UR8                  UR:                  UR<                  5        g! [>        R@                   aL  n	[B        RD                  RG                  SRI                  [J        RL                  " U	5      5      5         Sn	A	gSn	A	ff = f)zReport the anonymous crash information to the Error Reporting service.

This will report the actively handled exception.
Args:
  is_crash: bool, True if this is a crash, False if it is a user error.
NReport)error_messageserviceversionprojectrequest_urluserz&Unable to report crash stacktrace:
{0})'r   IsDefaultUniverseVALUEScoredisable_usage_reportingGetBool	traceback
format_excr   %RemovePrivateInformationFromTracebackr
   command_nameGetGetCIDIfMetricsEnabledr5   r   ErrorReportingprojects_eventsGetMethodConfigGenerateReportRequestSERVICEr   CLOUD_SDK_VERSIONCRASH_PROJECTERROR_PROJECTPrepareHttpRequestCustomBeaconurlhttp_methodbodyheadersapitools_exceptionsErrorr	   file_only_loggerr   r   r   SafeText)
r2   
stacktracer   cidclientreportermethod_configrequesthttp_requestes
             r   ReportErrorrc   o   s    
&
&
(
(44<<>>
 ##%*#II*%%22668'&&(#x(&  (('**::8DM,, ((!)} - 'G ))<< L))<+C+C%**L,@,@B 
	"	" '188!!!$	&' ''s   'B-F G5)AG00G5c                    [         R                  " U 5      n[        R                  R	                  S5        [        U 5      (       a  [        X5        g[        R                  " SR                  [        U S[        U 5      R                  5      U5      5        SU;   a]  [        R                  R                  S5        [        R                  R                  S5        [        R                  R                  S5        [        SS	9  [        R                  R                  S
5        [        R                  R                  S5        [        R                  R                  S5        [        R                  R                  S5        g)zhChecks if installation error occurred, then proceeds with Error Reporting.

Args:
  err: Exception err.
zBEGIN CRASH STACKTRACEzgcloud crashed ({0}): {1}
error_namezcertificate verify failedz{
gcloud's default CA certificates failed to verify your connection, which can happen if you are behind a proxy or firewall.zGTo use a custom CA certificates file, please run the following command:z?  gcloud config set core/custom_ca_certs_file /path/to/ca_certsT)r2   zJ
If you would like to report this issue, please run the following command:z  gcloud feedbackzG
To check gcloud for common problems, please run the following command:z  gcloud info --run-diagnosticsN)r   rZ   r	   rY   	exceptionr   r%   r   r   getattrtype__name__r   Printrc   r#   s     r   HandleGcloudCrashrk      s    $$S)*  !9:s##S-II)00\49#5#56
D E"j0	ggmmFG 
ggmm ) *	ggmm
KMGGMM ' (GGMM%&GGMM ' (GGMM34r   c                 F   ^  [         R                  " T 5      U 4S j5       nU$ )zContext manager for handling gcloud crashes.

Good for wrapping multiprocessing and multithreading target functions.

Args:
  target_function (function): Unit test to decorate.

Returns:
  Decorator function.
c                     >  T" U 0 UD6  g ! [          ac  n[        U5        [        R                  R                  R
                  R                  5       (       a  e [        R                  " S5         S nAg S nAff = f)Nr   )		Exceptionrk   r   r?   r@   print_unhandled_tracebacksrB   r    exit)argskwargsrb   target_functions      r   WrapperCrashManager.<locals>.Wrapper   s`    t&v& 							:	:	B	B	D	D 		s    
A9AA44A9)	functoolswraps)rs   rt   s   ` r   CrashManagerrx      s'     ???# $ 
.r   )T)$__doc__rv   r    rC   apitools.base.pyr   rW   &googlecloudsdk.api_lib.error_reportingr   googlecloudsdk.api_lib.utilr   r+   googlecloudsdk.callioper   googlecloudsdk.command_libr   googlecloudsdk.corer   r	   r
   r   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   r   r%   rP   r1   rM   rO   r0   r5   rc   rk   rx    r   r   <module>r      ss       
  > 7 9 3 ; & # ' * 4 .
7!H (A 
#A &%'P5<r   