
                            S 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J	r	  SSK
r
 " S S\5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rSS jrS rS rg)z"Base exceptions for the Cloud SDK.    )absolute_import)division)unicode_literalsN)encodingc                       \ rS rSrSrSrg)_Error   zXA base exception for all Cloud SDK errors.

This exception should not be used directly.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r
       %lib/googlecloudsdk/core/exceptions.pyr   r      s     r   r   c                       \ rS rSrSrSrg)InternalError'   z5A base class for all non-recoverable internal errors.r
   Nr   r
   r   r   r   r   '   s    =r   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )Error,   a.  A base exception for all user recoverable errors.

Any exception that extends this class will not be printed with a stack trace
when running from CLI mode.  Instead it will be shows with a message of how
the user can correct this problem.

All exceptions of this type must have a message for the user.
c                 V   > [         [        U ]
  " U6   UR                  SS5      U l        g)zInitialize a core.Error.

Args:
  *args: positional args for exceptions.
  **kwargs: keyword args for exceptions, and additional arguments:
    - exit_code: int, The desired exit code for the CLI.
	exit_code   N)superr   __init__getr   )selfargskwargs	__class__s      r   r   Error.__init__6   s&     
%&ZZQ/DNr   )r   r   r   r   r   r   r   r   __classcell__r#   s   @r   r   r   ,   s    	0 	0r   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )
MultiErrorB   z2Collection of Error instances as single exception.c                 X   > [         [        U ]  SR                  S U 5       5      5        g )Nz, c              3   N   #    U  H  n[         R                  " U5      v   M     g 7fN)six	text_type).0es     r   	<genexpr>&MultiError.__init__.<locals>.<genexpr>G   s     "DV3==#3#3Vs   #%)r   r)   r   join)r    errorsr#   s     r   r   MultiError.__init__E   s%    	*
"DV"DDEr   r
   r%   r'   s   @r   r)   r)   B   s    :F Fr   r)   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )RequiresAdminRightsErrorJ   zAn exception for when you don't have permission to modify the SDK.

This tells the user how to run their command with administrator rights so that
they can perform the operation.
c                 0  > SSK Jn  SR                  US9nUR                  R	                  5       UR                  R
                  :X  a  US-  nO5[        R                  R                  USS5      nUSR                  U5      -  n[        [        U ]/  U5        g )	Nr   )	platformszYou cannot perform this action because you do not have permission to modify the Google Cloud SDK installation directory [{root}].

)rootzClick the Google Cloud SDK Shell icon and re-run the command in that window, or re-run the command with elevated privileges by right-clicking cmd.exe and selecting "Run as Administrator".bingcloudz*Re-run the command with sudo: sudo {0} ...)googlecloudsdk.core.utilr;   formatOperatingSystemCurrentWINDOWSospathr4   r   r8   r   )r    sdk_rootr;   messagegcloud_pathr#   s        r   r   !RequiresAdminRightsError.__init__Q   s    2	N	X	  	!!))+!!))	*IJg GGLL5(;k
6
=
=k
JLg	
"D27;r   r
   r%   r'   s   @r   r8   r8   J   s    < <r   r8   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )NetworkIssueErrori   z)An error to wrap a general network issue.c                 n   > [         [        U ]  SR                  [        R
                  " U5      S95        g )Nz{message}
This may be due to network connectivity issues. Please check your network settings, and the status of the service you are trying to reach.)rG   )r   rK   r   r@   r   Decode)r    rG   r#   s     r   r   NetworkIssueError.__init__l   s/    	
T+	  89	;r   r
   r%   r'   s   @r   rK   rK   i   s    1; ;r   rK   c                   $    \ rS rSrSrS rS rSrg)ExceptionContextt   a0  An exception context that can be re-raised outside of try-except.

Usage:
  exception_context = None
  ...
  try:
    ...
  except ... e:
    # This MUST be called in the except: clause.
    exception_context = exceptions.ExceptionContext(e)
  ...
  if exception_context:
    exception_context.Reraise()
c                     Xl         [        R                  " 5       S   U l        U R                  (       d  [	        S5      eg )N   z2Must set ExceptionContext within an except clause.)
_exceptionsysexc_info
_tracebackr   )r    r1   s     r   r   ExceptionContext.__init__   s3    OllnQ'DO
 ??NOO r   c                     [         R                  " [        U R                  5      U R                  U R                  5        g r-   )r.   reraisetyperU   rX   )r    s    r   ReraiseExceptionContext.Reraise   s#    KKT__%tHr   )rU   rX   N)r   r   r   r   r   r   r]   r   r
   r   r   rQ   rQ   t   s    PIr   rQ   c                     U=(       d    [         R                  " 5       S   n[        R                  " [	        U 5      X5        g)z?Adds tb or the most recent traceback to exc_value and reraises.rT   N)rV   rW   r.   r[   r\   )	exc_valuetbs     r   r[   r[      s)    	S\\^A"++d9oy-r   c                     / n[         R                  " XU5       H(  nUR                  [        R                  " U5      5        M*     SR                  U5      $ )zFReturns a formatted exception message from an exception and traceback. )	tracebackformat_exceptionappendr   rN   r4   )exc_typeexc	exc_traceexc_msg_lineslines        r   _FormatExceptionrl      sE    -((	Bd./ C		r   c                     [         R                  (       a  U(       d  Ue[        XU5      n[        X4U5      nSR                  Xg5      n[         R                  " X3" U5      U5        g)a'  Raises an exception that occurs when handling another exception.

Python 3 does this sort of exception chaining natively, but it's not supported
in Python 2. So when running in Python 2, we manually reproduce the error
message we would get it in Python 3. It won't look identical but it's good
enough for debugging purposes so that we don't lose the exception context.

Args:
  orig_exc_type: The type of the original exception being handled.
  orig_exc: The original exception.
  orig_exc_trace: The traceback of the original exception.
  curr_exc_type: The type of the current exception being handled.
  curr_exc: The current exception.
  curr_exc_trace: The traceback of the current exception.

Raises:
  Exception: The current exception with added context from the original
    exception being handled.
zL

{}
During handling of the above exception, another exception occurred:

{}N)r.   PY2rl   r@   r[   )	orig_exc_typeorig_excorig_exc_tracecurr_exc_typecurr_exccurr_exc_traceorig_exc_msgcurr_exc_msgnew_exc_msgs	            r   RaiseWithContextrx      sU    , 

N!->J,!->J,vl1  ++m];7Hr   r-   )r   
__future__r   r   r   rD   rV   rd   r?   r   r.   	Exceptionr   r   r   r)   r8   rK   objectrQ   r[   rl   rx   r
   r   r   <module>r|      s     ) &  ' 	 
  - 
Y F 
0F 0,F F<u <>; ;Iv I<. Ir   