
                         n   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 G d dej                        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y) zCalliope parsing errors for logging and collecting metrics.

Refer to the calliope.parser_extensions module for a detailed overview.
    )absolute_import)division)unicode_literalsNc                   .     e Zd ZdZ	 	 d fd	Zd Z xZS )ArgumentErrora
  Base class for argument errors with metrics.

  ArgumentError instances are intercepted by
  parser_extensions.ArgumentParser.error(), which
    1. reports a failed command to metrics
    2. prints a usage diagnostic to the standard error
    3. exits with status 2, bypassing gcloud_main exception handling

  Attributes:
    argument: str, The argument name(s) causing the error.
    error_extra_info: {str: str}, Extra info dict for error_format.
    error_format: str, A .format() string for constructng the error message
      from error_extra_info.
    extra_path_arg: str, Dotted command path to append to the command path.
    parser: ArgmentParser, Used to generate the usage string for the command.
      This could be a different subparser than the command parser.
  c                     || _         || _        || _        || _        || _        t
        t        |   d t        j                  |              y )N)
error_formatargumentextra_path_argparsererror_extra_infosuperr   __init__six	text_type)selfr	   r
   r   r   kwargs	__class__s         ,lib/googlecloudsdk/calliope/parser_errors.pyr   zArgumentError.__init__0   sC    $DDM(DDK"D	-'cmmD.AB    c                 Z   t        di | j                  }	 	  | j                  j                  di |}	 | j                  rdj                  | j                  |      }|S # t        $ r$}|j
                  d   }d|z   dz   ||<   Y d }~n$d }~wt        t        f$ r | j                  }Y sw xY w)Nr   {}zargument {argument}: {message})r
   message )	dictr   r	   formatKeyErrorargs
IndexError
ValueErrorr
   )r   keysr   ekeys        r   __str__zArgumentError.__str__9   s    ($''(D

*$##**2T2 }}077==' 8 3gN  $ffQi#IOS	*% ## s   A   	B))BB)(B))NNN)__name__
__module____qualname____doc__r   r%   __classcell__r   s   @r   r   r      s    $ BFCr   r   c                       e Zd ZdZy)OtherParsingErrorz6Some other parsing error that is not any of the above.Nr&   r'   r(   r)   r   r   r   r-   r-   M   s    >r   r-   c                       e Zd ZdZy)TooFewArgumentsErrorz/Argparse didn't use all the Positional objects.Nr.   r   r   r   r0   r0   Q   s    7r   r0   c                       e Zd ZdZy)UnknownCommandErrorzUnknown command error.Nr.   r   r   r   r2   r2   U   s    r   r2   c                       e Zd ZdZy)UnrecognizedArgumentsErrorz<User entered arguments that were not recognized by argparse.Nr.   r   r   r   r4   r4   Y       Dr   r4   c                       e Zd ZdZy)DetailedArgumentErrorz:A DetailedArgumentError is preferable to an ArgumentError.Nr.   r   r   r   r7   r7   ]   s    Br   r7   c                   "     e Zd ZdZ fdZ xZS )ModalGroupErrorzModal group conflict error.c                 2    t        t        | 
  	 dd|i| y )Nconflict)z{conflict} must be specified.)r   r9   r   r   r;   r   r   s      r   r   zModalGroupError.__init__d   s'    	/4)' r   r&   r'   r(   r)   r   r*   r+   s   @r   r9   r9   a   s    # r   r9   c                   "     e Zd ZdZ fdZ xZS )OptionalMutexErrorzOptional mutex conflict error.c                 2    t        t        | 
  	 dd|i| y )Nr;   )z+At most one of {conflict} can be specified.)r   r?   r   r<   s      r   r   zOptionalMutexError.__init__n   s(    	
d,5 r   r=   r+   s   @r   r?   r?   k       & r   r?   c                   "     e Zd ZdZ fdZ xZS )RequiredErrorzRequired error.c                 .    t        t        | 
  	 di | y )N)zMust be specified.)r   rC   r   )r   r   r   s     r   r   zRequiredError.__init__x   s    	-'
r   r=   r+   s   @r   rC   rC   u   s     r   rC   c                   "     e Zd ZdZ fdZ xZS )RequiredMutexErrorzRequired mutex conflict error.c                 2    t        t        | 
  	 dd|i| y )Nr;   )z,Exactly one of {conflict} must be specified.)r   rF   r   r<   s      r   r   zRequiredMutexError.__init__   s(    	
d,6 r   r=   r+   s   @r   rF   rF   ~   rA   r   rF   c                       e Zd ZdZy)WrongTrackErrorz)For parsed commands in a different track.Nr.   r   r   r   rI   rI      s    1r   rI   c                       e Zd ZdZy)ArgumentExceptionz>ArgumentException is for problems with the declared arguments.Nr.   r   r   r   rK   rK      s    Fr   rK   c                       e Zd ZdZy)UnknownDestinationExceptionz<Fatal error for an internal dest that has no associated arg.Nr.   r   r   r   rM   rM      r5   r   rM   )r)   
__future__r   r   r   argparser   r   r-   r0   r2   r4   r7   r9   r?   rC   rF   rI   	ExceptionrK   rM   r   r   r   <module>rQ      s    
 '  '  
-H** -`? ?8= 8- E ECM C+ . ) . 2+ 2G	 GE) Er   