
    wBf7                     n    d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	m
Z
  ee      Z G d d      Zd	 Zy)
z#Error handling and error reporting.    N)	lru_cachepartial	getLogger   )ensure_text_typeon_winc                       e Zd Zd Zd Zed        Zed        Zed        Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Ze ed      d               ZddZd Zd Zd Zy)ExceptionHandlerc                 v    	  ||i |S #  t        j                         \  }}}| j                  ||      cY S xY wN)sysexc_infohandle_exception)selffuncargskwargs_exc_valexc_tbs          7lib/python3.12/site-packages/conda/exception_handler.py__call__zExceptionHandler.__call__   sC    	:(((	:!$Aw((&99s   
 ,8c                 v    ddl m} ddlm}  |         |d      j	                  dj                  |             y )Nr   r   r   )init_loggerszconda.stderr
)loggingr   cli.mainr   infojoin)r   contentr   r   s       r   	write_outzExceptionHandler.write_out   s)    %*.!&&tyy'9:    c                 >    ddl m} |j                  |j                  fS Nr   context)base.contextr'   remote_connect_timeout_secsremote_read_timeout_secsr   r'   s     r   http_timeoutzExceptionHandler.http_timeout   s    )22G4T4TTTr#   c                 &    ddl m} |j                  S r%   )r(   r'   
user_agentr+   s     r   r.   zExceptionHandler.user_agent%   s    )!!!r#   c                 &    ddl m} |j                  S r%   )r(   r'   error_upload_urlr+   s     r   r0   z!ExceptionHandler.error_upload_url+   s    )'''r#   c                    ddl m} ddlm}m}m} t        ||      r0|j                  r| j                  ||      S | j                  ||      S t        |t              r(t        |dd       |k(  r| j                   ||      |      S t        |t              r| j                   ||      |      S t        |t              r| j                   |d      |       yt        |t              r|j                   S | j#                  ||      S )Nr   )ENOSPCr   )
CondaErrorCondaMemoryErrorNoSpaceLeftErrorerrnoKeyboardInterrupt)r6   r2   
exceptionsr3   r4   r5   
isinstance
reportable'handle_reportable_application_exceptionhandle_application_exceptionEnvironmentErrorgetattrMemoryErrorr7   _print_conda_exception
SystemExitcodehandle_unexpected_exception)r   r   r   r2   r3   r4   r5   s          r   r   z!ExceptionHandler.handle_exception1   s     	
 	
 gz*!!CCGVTT88&IIg/0w.&888$W-v  g{+445Eg5NPVWWg01''
3F(GPgz*<<//@@r#   c                 >    | j                  ||       |j                  S r   )r@   return_code)r   r   r   s      r   r<   z-ExceptionHandler.handle_application_exceptionM   s    ##GV4"""r#   c                 "    ddl m}  |||       y )Nr   )print_conda_exception)r8   rG   )r   r   r   rG   s       r   r@   z'ExceptionHandler._print_conda_exceptionQ   s    5gv.r#   c                     | j                  ||      }| j                  |       | j                  |       t        |dd       }||S dS )NrE   r   )get_error_reportprint_unexpected_error_report_uploadr>   )r   r   r   error_reportrcs        r   rC   z,ExceptionHandler.handle_unexpected_exceptionV   sK    ,,Wf=**<8\"WmT2^r**r#   c                     | j                  ||      }ddlm} |j                  r|j	                  |j                                | j                  |       | j                  |       |j                  S r%   )	rI   r(   r'   jsonupdatedump_mapprint_expected_error_reportrK   rE   )r   r   r   rL   r'   s        r   r;   z8ExceptionHandler.handle_reportable_application_exception]   s[    ,,Wf=)<< 0 0 23((6\""""r#   c                    ddl m}m} dj                  d t        j
                  D              }i }d|vr	 ddlm}  |       }t        |      |j                  j                  t        |j                        | |||      |d}
t        ||      r|j                         |
d	<   |
S # t        $ rH} |       }	t        |      |j                  j                  t        |j                        |	d}Y d }~d }~ww xY w)
Nr   )r3   _format_exc c              3   2   K   | ]  }t        |        y wr   )r   ).0ss     r   	<genexpr>z4ExceptionHandler.get_error_report.<locals>.<genexpr>j   s     A1+A.As   z info)get_info_dict)errorexception_nameexception_type	traceback)r[   r\   r]   commandr^   
conda_infoconda_error_components)r8   r3   rT   r    r   argvcli.main_inforZ   	Exceptionrepr	__class____name__strr9   rQ   )r   r   r   r3   rT   r_   	info_dictrZ   info_einfo_tracebackrL   s              r   rI   z!ExceptionHandler.get_error_reportg   s    7((AAA	'!8)O	 ']%//88!'"3"34$Wf5#
 gz*5<5E5E5GL12+  !,!&\&,&6&6&?&?&)'*;*;&<!/		s   B$ $	C5->C00C5c                    ddl m} |j                  rddlm}  ||       y g }|j                  d       |j                  d       |j                  d       |j                  d |d   j                         D               |j                  d       |j                  d|d	   z         |j                  d       |d
   r=ddlm	}m
} 	 |j                   ||d
                |j                   ||d
                |j                  g d        | j                  |  y # t        $ rG}t        j                  d|d       |j                  d       |j                  d|z         Y d }~nd }~ww xY w)Nr   r&   stdout_json <# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<c              3   &   K   | ]	  }d |z     yw)z    N )rW   lines     r   rY   zAExceptionHandler.print_unexpected_error_report.<locals>.<genexpr>   s      #"&#s   r^   `$ %s`r_   r`   get_env_vars_strget_main_info_str%rTr   $conda info could not be constructed.)ro   zFAn unexpected error has occurred. Conda has prepared the above report.zEIf you suspect this error is being caused by a malfunctioning plugin,z;consider using the --no-plugins option to turn off plugins.ro   z-Example: conda --no-plugins install <package>ro   zGAlternatively, you can set the CONDA_NO_PLUGINS environment variable onz<the command line to run the command without plugins enabled.ro   z6Example: CONDA_NO_PLUGINS=true conda install <package>ro   )r(   r'   rO   
cli.commonrn   appendextend
splitlinesrc   rv   rw   rd   logwarnr"   r   rL   r'   rn   message_builderrv   rw   es           r   rJ   z.ExceptionHandler.print_unexpected_error_report   s[   )<</% O""2&""N ""2&"" #*6{*C*N*N*P#  ""2&""8l9.E#EF""2&L)N	5#**+;L<V+WX#**),|*DE """ DNNO,+ ! 5HHT1tH4#**+QR#**4!8445s   4D 	E.'=E))E.c                 X   ddl m} |j                  rddlm}  ||       y g }|j                  d       |j                  d       |j                  d       |j                  d|d   z         |j                  d       |d   r=dd	lm}m} 	 |j                   ||d                |j                   ||d                |j                  d       |j                  d       |j                  d       |j                  |d   j                                |j                  d       |j                  d       |j                  d        | j                  |  y # t        $ rG}t        j                  d
|d       |j                  d       |j                  d
|z         Y d }~d }~ww xY w)Nr   r&   rm   ro   rp   rt   r_   r`   ru   rx   Try   rz   z=V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V Vr[   zQA reportable application error has occurred. Conda has prepared the above report.)r(   r'   rO   r{   rn   r|   rc   rv   rw   rd   r   r   r}   r~   r"   r   s           r   rR   z,ExceptionHandler.print_expected_error_report   s   )<</% O""2&""N ""2&""8l9.E#EF""2&L)N	5#**+;L<V+WX#**),|*DE ""2&""O ""2&""<#8#C#C#EF""2&""c ""2&DNNO,# ! 5HHT1tH4#**+QR#**4!8445s   4E 	F)"=F$$F)N)maxsizec                     	 t        j                  d      xs t        S # t        $ r }t        j                  d|       Y d }~yd }~ww xY w)Nr   rx   T)osisattyr	   rd   r   debug)r   r   s     r   _isattyzExceptionHandler._isatty   s;    	99Q<)6) 	IIdA	s    	AAAc                 t   ddl m} d}|j                  du rd}nx|j                  du s|j                  rd}n[|j                  s|j
                  s| j                  s%t        |j                   xr |j                        }n| j                         }d}|r| j                  |       |r| j                  |       yy)z4Determine whether or not to upload the error report.r   r&   FTN)r(   r'   report_errors
always_yesrO   quietr   booloffline_ask_upload_execute_upload_post_upload)r   rL   r'   post_upload	do_uploads        r   rK   zExceptionHandler._upload   s    )  E)I""d*g.@.@I\\W]]$,,0GW5G5GHI ((*IK   .i( r#   c                     ddl m} ddlm} 	  |dt	        t
        d            }|xr  ||      S # t        $ r }t        j                  d|       Y d }~yd }~ww xY w)Nr   )boolify)timeout(   zIf submitted, this report will be used by core maintainers to improve
future releases of conda.
Would you like conda to send this report to the core maintainers? [y/N]: rx   F)	auxlib.type_coercionr   	common.ior   r   inputrd   r   r   )r   r   r   r   r   s        r   r   zExceptionHandler._ask_upload  s]    1&		I 3!33 	IIdA	s   "1 	AAAc                    dd l }dd l}ddlm} d| j                  i}| j
                  }|j                         }t        d |D              rdnd|d<   d	t        |      v rdnd|d
<   |j                  |d|      dz   }|j                  t        |      d      }d }		 dd l}
d}| j                  }|
j                  ||||d      }	|	j                          |	j                  dv r|	j                   j#                  d      rw|	j                   d   }|
j                  ||||d      }	|	j                          |dz  }|dkD  rddlm}  |d      |	j                  dv r|	j                   j#                  d      rwt(        j+                  d|	xr |	j                         	 |	r|	j0                  r| j3                  d       y | j3                  d       |	r,|	j                  r| j3                  d|	j                  z         y y y # t,        $ r }t(        j/                  d|       Y d }~d }~ww xY w# t,        $ r"}t(        j+                  d|z         Y d }~y d }~ww xY w)Nr   r   )EntityEncoderz
User-Agentc              3   8   K   | ]  }t        |      d k    yw)   N)ord)rW   cs     r   rY   z3ExceptionHandler._execute_upload.<locals>.<genexpr>4  s     7A7s   TFis_asciirU   
has_spaces)	sort_keysclsr   USERNAME_REMOVED)headersr   dataallow_redirects)i-  i.  Location   )r3   zRedirect limit exceededzupload response status: %srx   zUpload successful.zUpload did not complete.z HTTP %s)getpassrO   auxlib.entityr   r.   r,   getuserallrh   dumpsreplacerequestsr0   postraise_for_statusstatus_coder   getro   r3   r   r   rd   r   okr"   )r   rL   r   rO   r   r   _timeoutusernamer   responser   redirect_counterurlr3   r   s                  r   r   z ExceptionHandler._execute_upload(  sH   0 $//
 $$??$7h77DU 	Z  .1CM-ATu\"zz,$MzJTQ||CM+=>	  ''C}}WhTSX % H %%'&&*49I9I9M9M: &&z2#==#$$) )  ))+ A% #b(,$%>??! &&*49I9I9M9M:" II2H4UAUAUV	 HKK349: 4 4NN:0D0D#DE !58  	HHT1	  	 IIdQh	 s=   CG8 3$G8 H$ 8=H$ 8	H!HH!$	I-I

Ic           	          |du r| j                  ddddddd       y || j                  ddd       y | j                  dddd	d       y )
NTro   z'Thank you for helping to improve conda.zAOpt-in to always sending reports (and not see this message again)z
by runningz+    $ conda config --set report_errors truez Timeout reached. No report sent.z+No report sent. To permanently opt-out, usez,    $ conda config --set report_errors false)r"   )r   r   s     r   r   zExceptionHandler._post_uploadd  se    NN9S= NN2 NN=>r#   )returnN)rg   
__module____qualname__r   r"   propertyr,   r.   r0   r   r<   r@   rC   r;   rI   rJ   rR   r   r   rK   r   r   r   rr   r#   r   r   r      s    :; U U
 " "
 ( (
A8#/
+#!F2-h*-Z t  )@(: xr#   r   c                 2    t               } || g|i |}|S r   )r   )r   r   r   exception_handlerreturn_values        r   conda_exception_handlerr     s%    (*$T;D;F;Lr#   )__doc__r   r   	functoolsr   r   r   r   common.compatr   r	   rg   r   r   r   rr   r#   r   <module>r      s5    * 	 
 (  3p pfr#   