
    x%                        d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ	 ddl
mZ ddlmZ ddlZdZdZ G d	 d
ej                         Z G d dej                         Z G d dej                         Z G d dej                         Z G d dej                         Z G d dej                         Z G d dej                         Z G d dej                         Z G d dej                         Z G d dej                         Z G d dej                         Z G d d ej                         Z G d! d"ej                         Z G d# d$ej                         Z G d% d&ej                         Z G d' d(ej                         Z  G d) d*ej                         Z! G d+ d,ej                         Z" G d- d.ejF                        Z$ G d/ d0e      Z% G d1 d2e      Z& G d3 d4ej                         Z' G d5 d6e'      Z( G d7 d8ej                         Z) G d9 d:ej                         Z* G d; d<ej                         Z+ G d= d>e	jX                        Z- G d? d@ej                         Z. ej^                  dAej`                        Z1dOdBZ2 G dC dDej                         Z3 G dE dFej                         Z4 G dG dHe5      Z6 G dI dJej                         Z7 G dK dLej                         Z8 G dM dNejr                        Z:y)Pz:This module holds exceptions raised by Cloud Run commands.    )absolute_import)division)unicode_literalsN)
exceptionsz=You could deploy using GPUs without zonal redundancy instead.zOYou could deploy with --no-gpu-zonal-redundancy flag attached to your command.
c                   "     e Zd ZdZ fdZ xZS )SelfDocumentingErrorzAn error that uses its own docstring as its message if no message given.

  Somehow I think this was how all errors worked maybe back when this was Python
  2, and it got lost in the shuffle at some point.
  c                 \    || j                   j                  }t        t        |   |       y N)	__class____doc__superr   __init__)selfmessager   s     0lib/googlecloudsdk/command_lib/run/exceptions.pyr   zSelfDocumentingError.__init__.   s'    &&g	
.w7    __name__
__module____qualname__r   r   __classcell__r   s   @r   r   r   '   s    8 8r   r   c                       e Zd ZdZy)BucketAccessErrorz2Indicates a failed attempt to access a GCS bucket.Nr   r   r   r    r   r   r   r   4       :r   r   c                       e Zd ZdZy)CancellationFailedErrorzIndicates failure to cancel.Nr   r   r   r   r   r   8       $r   r   c                       e Zd ZdZy)DeletionFailedErrorzIndicates failure to delete.Nr   r   r   r   r"   r"   <   r    r   r"   c                       e Zd ZdZy)ConfigurationErrorz$Indicates an error in configuration.Nr   r   r   r   r$   r$   @   s    ,r   r$   c                       e Zd ZdZy)ServiceNotFoundErrorz5Indicates that a provided service name was not found.Nr   r   r   r   r&   r&   D       =r   r&   c                       e Zd ZdZy)RevisionNotFoundErrorz6Indicates that a provided revision name was not found.Nr   r   r   r   r)   r)   H   s    >r   r)   c                       e Zd ZdZy)JobNotFoundErrorz1Indicates that a provided job name was not found.Nr   r   r   r   r+   r+   L   s    9r   r+   c                       e Zd ZdZy)ExecutionNotFoundErrorz7Indicates that a provided execution name was not found.Nr   r   r   r   r-   r-   P   s    ?r   r-   c                       e Zd ZdZy)WorkerNotFoundErrorz4Indicates that a provided worker name was not found.Nr   r   r   r   r/   r/   T   s    <r   r/   c                       e Zd ZdZy)DockerVersionErrorz5Indicates an error in determining the docker version.Nr   r   r   r   r1   r1   X   r'   r   r1   c                       e Zd ZdZy)AmbiguousContainerErrorzGMore than one container fits our criteria, we do not know which to run.Nr   r   r   r   r3   r3   \   s    Or   r3   c                       e Zd ZdZy)CloudSQLErrorz(Malformed instances string for CloudSQL.Nr   r   r   r   r5   r5   `       0r   r5   c                       e Zd ZdZy)ContainerIdErrorz'Container Id cannot be found by docker.Nr   r   r   r   r8   r8   d       /r   r8   c                       e Zd ZdZy)NoActiveRevisionsErrorz-Active revisions were expected but not found.Nr   r   r   r   r;   r;   h   s    5r   r;   c                       e Zd ZdZy)SourceNotSupportedErrorz:Your Cloud Run install does not support source deployment.Nr   r   r   r   r=   r=   l   s    Br   r=   c                       e Zd ZdZy)NoConfigurationChangeErrorz(No configuration changes were requested.Nr   r   r   r   r?   r?   p   r6   r   r?   c                       e Zd ZdZy)UnknownDeployableErrorz>Could not identify the deployable app, function, or container.Nr   r   r   r   rA   rA   t   s    Fr   rA   c                       e Zd ZdZy)AppNotReadyErrorz;The application must be uploaded before it can be deployed.Nr   r   r   r   rC   rC   x   s    Cr   rC   c                       e Zd ZdZy)DeploymentFailedErrorz+An error was encountered during deployment.Nr   r   r   r   rE   rE   |       3r   rE   c                       e Zd ZdZy)ExecutionFailedErrorzThe execution failed.Nr   r   r   r   rH   rH      s    r   rH   c                       e Zd ZdZy)DomainMappingCreationErrorzAAn error was encountered during the creation of a domain mapping.Nr   r   r   r   rJ   rJ      s    Ir   rJ   c                       e Zd ZdZy)DomainMappingAlreadyExistsErroras  Domain mapping already exists in another project, GCP service, or region.

  This indicates a succesfully created DomainMapping resource but with the
  domain it intends to map being unavailable because it's already in use.
  Not to be confused with a 409 error indicating a DomainMapping resource with
  this same name (the domain name) already exists in this region.
  Nr   r   r   r   rL   rL      s    r   rL   c                       e Zd ZdZy)PlatformErrorz'Command not supported for the platform.Nr   r   r   r   rN   rN      r9   r   rN   c                       e Zd Zy)ArgumentErrorN)r   r   r   r   r   r   rP   rP      s    r   rP   c                       e Zd ZdZy)
NoTLSErrorzTLS 1.2 support is required to connect to GKE.

  Your Python installation does not support TLS 1.2. For Python2, please upgrade
  to version 2.7.9 or greater; for Python3, please upgrade to version 3.4 or
  greater.
  Nr   r   r   r   rR   rR      s    r   rR   c                   "     e Zd ZdZ fdZ xZS )	HttpErrorz(More prettily prints apitools HttpError.c                 0   t         t        |   |       | j                  j                  rdj                  | j                  j                  j                         D cg c]  }dj                  |       c}      | _        | j                  j                  j                         D ]j  }t        | j                  j                  |   v s#| j                  j                  |   j                  t        t              | j                  j                  |<   l y y c c}w )N
z{0}: {{field_violations.{0}}})r   rT   r   payloadfield_violationsjoinkeysformaterror_formatREDEPLOY_GPU_MESSAGEreplaceREDEPLOY_GPU_WITH_FLAG_MESSAGE)r   errorkr   s      r   r   zHttpError.__init__   s    	)T#E*||$$))<<00557%7a *
0
0
37% 	d
 ||,,113!4<<#@#@#CC-1\\-J-J.G(*HI ,,
'
'
* 4 %%s   Dr   r   s   @r   rT   rT      s    0J Jr   rT   c                       e Zd ZdZy)FieldMismatchErrorz2Given field value doesn't match the expected type.Nr   r   r   r   rc   rc      r   r   rc   zG^.*(?:\n.*)*Expected type .+? for field (.+?), found (.+?) \(type .+?\)c                 D   t         j                  t        |             }|r|j                  d      dk(  r)t	        dj                  |j                  d                  |j                  d      dk(  r.t	        dj                  t        j                  |       |            | )a  Special handling for port field type mismatch.

  Due to differences in golang structs used by clusters and proto messages used
  by gcloud, some invalid service responses should be specially handled.
  See b/149365868#comment5 for more info.

  Args:
    error: original error complaining of a type mismatch.
    help_text: str, a descriptive message to help with understanding the error.

  Raises:
    FieldMismatchError: If the error is due to our own custom handling or the
      original error if not.
     portzError decoding the "port" field. Only integer ports are supported by gcloud. Please change your port from "{}" to an integer value to be compatible with gcloud.   valuez{0}
{1})VALIDATION_ERROR_MSG_REGEXmatchstrgrouprc   r[   six	text_type)r`   	help_textregex_matchs      r   MaybeRaiseCustomFieldMismatchrq      s     +00U<+v%''-vk.?.?.B'C 
 
		1		(


CMM%0)
<  	+r   c                       e Zd ZdZy)KubernetesErrorz+A generic kubernetes error was encountered.Nr   r   r   r   rs   rs      rF   r   rs   c                       e Zd ZdZy)UnsupportedOperationErrorz)The requested operation is not supported.Nr   r   r   r   ru   ru      s    1r   ru   c                       e Zd ZdZd Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zed        Zy)KubernetesExceptionParserz-Converts a kubernetes exception to an object.c                 Z    || _         t        j                  |j                        | _        y)zWraps a generic http error returned by kubernetes.

    Args:
      http_error: apitools.base.py.exceptions.HttpError, The error to wrap.
    N)_wrapped_errorjsonloadscontent_content)r   
http_errors     r   r   z"KubernetesExceptionParser.__init__   s"     %DJJz112DMr   c                 N    	 | j                   j                  S # t        $ r Y y w xY wr
   )ry   status_codeKeyErrorr   s    r   r   z%KubernetesExceptionParser.status_code   s+      ,,, s    	$$c                 .    | j                   j                  S r
   )ry   urlr   s    r   r   zKubernetesExceptionParser.url   s    """r   c                 @    	 | j                   d   S # t        $ r Y y w xY w)N
apiVersionr}   r   r   s    r   api_versionz%KubernetesExceptionParser.api_version  s(    ]]<((     	c                 F    	 | j                   d   d   S # t        $ r Y y w xY w)Ndetailsrl   r   r   s    r   api_namez"KubernetesExceptionParser.api_name	  s-    ]]9%g..     	  c                 F    	 | j                   d   d   S # t        $ r Y y w xY w)Nr   namer   r   s    r   resource_namez'KubernetesExceptionParser.resource_name  -    ]]9%f-- r   c                 F    	 | j                   d   d   S # t        $ r Y y w xY w)Nr   kindr   r   s    r   resource_kindz'KubernetesExceptionParser.resource_kind  r   r   c                 @    	 | j                   d   S # t        $ r Y y w xY w)Nr   r   r   s    r   default_messagez)KubernetesExceptionParser.default_message  s(    ]]9%% r   c                     | j                   S r
   )ry   r   s    r   r`   zKubernetesExceptionParser.error%  s    r   c                     	 | j                   d   d   D ci c]  }|d   |
 }}t        |      D cg c]  }||   	 c}S c c}w c c}w # t        $ r g cY S w xY w)z.Returns list of causes uniqued by the message.r   causesr   )r}   sortedr   )r   cmessagesra   s       r   r   z KubernetesExceptionParser.causes)  sp    +/==+CH+MN+Ma!I,/+MhN#)(#34#3ahqk#344 O4 is+   A AA AA 
A AAN)r   r   r   r   r   propertyr   r   r   r   r   r   r   r`   r   r   r   r   rw   rw      s    53   # #              r   rw   c                       e Zd ZdZy)BaseImageErrorz5An error was encountered when parsing the base image.Nr   r   r   r   r   r   3  r'   r   r   c                       e Zd ZdZy)ServiceAccountErrorz8Indicates error due to service account misconfiguration.Nr   r   r   r   r   r   7  s    @r   r   c                   "     e Zd ZdZ fdZ xZS )RequiredImageArgumentExceptionz3An exception for missing image flag for containers.c                 j    t         t        |   ddj                  dj	                  |                   y )Nz--imagez2Containers {} require a container image to deploy.z, )r   r   r   r[   rY   )r   
containersr   s     r   r   z'RequiredImageArgumentException.__init__>  s0    	
($8<CCIIj!	
r   r   r   s   @r   r   r   ;  s    ; r   r   ) );r   
__future__r   r   r   rz   regooglecloudsdk.api_lib.utilr   exceptions_utilgooglecloudsdk.calliopec_exceptionsgooglecloudsdk.corerm   r]   r_   Errorr   r   r   r"   r$   r&   r)   r+   r-   r/   r1   r3   r5   r8   r;   r=   r?   rA   InternalErrorrC   rE   rH   rJ   rL   rN   rP   rR   HttpExceptionrT   rc   compile	MULTILINEri   rq   rs   ru   objectrw   r   r   RequiredArgumentExceptionr   r   r   r   <module>r      s   A &  '  	 E > * 
 D  
8:++ 
8;
(( ;%j.. %%*** %-)) ->:++ >?J,, ?:z'' :@Z-- @=*** =>)) >Pj.. P1J$$ 10z'' 06Z-- 6Cj.. C1!1!1 1GZ-- GDz// D40 4/ J!1!1 J&@ 0J$$ 0J$$ !! J-- J$;)) ; (RZZNLL <4j&& 42
 0 0 2E EP>Z%% >A*** A	\%K%K 	r   