
    \j                        U d Z ddlZddlmZ ddlmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZ dedefdZde
defdZdedefd	Zdedefd
ZdedefdZdedefdZdedefdZdedefdZdedefdZi ed e
eeeeeeeed ed ed eeeeeee	d ed ed ed eeeeZ e!e"e#   edef   f   e$d<   de#dedz  fdZ%y)zCLI error handling utilities.    N)Callable)BucketNotFoundErrorCLIErrorCLIExtensionInstallErrorDeviceCodeErrorEntryNotFoundErrorGatedRepoErrorHfHubHTTPError
HfUriErrorIncompleteSnapshotErrorLocalEntryNotFoundErrorLocalTokenNotFoundErrorOfflineModeIsEnabled	OIDCErrorRemoteEntryNotFoundErrorRepositoryNotFoundErrorRevisionNotFoundErrorerrorreturnc                 X   | j                   r| j                   j                         nd}| j                  r| d| j                   d}n| d}|dz  }|dz  }| j                  B| j                   r| j                   dk7  rd| j                    nd	}|d
| j                   | z  }|S |dz  }|S )N
Repository '' not found.z not found.ze
If the repo is private, make sure you are authenticated and your token has the required permissions.z-
If the repo does not exist, create it with: modelz --type  zhf repos create zhf repos create <repo_id>)	repo_type
capitalizerepo_id)r   labelmsg	type_flags       N/root/.hermes/venv/lib/python3.12/site-packages/huggingface_hub/cli/_errors.py_format_repo_not_foundr#   '   s    ,1OOEOO&&(E}}r%--5{#ssC;;C}} 49OO[bHbhu/0hj	!%--<< J 	**J    c                     | j                   r| j                   nd}| j                  r!d|j                          d| j                   dS d| dS )N
repositoryzAccess denied. r   z' requires approval.zAccess denied. This z requires approval.)r   r   r   r   r   s     r"   _format_gated_repor(   9   sN    $EOOLE}} !1!1!3 4Bu}}oEYZZ!%(;<<r$   c                     | j                   r d| j                    d}d| j                    }nd}d}|dz  }|d| z  }|S )NzBucket 'r   zhf buckets create zBucket not found.zhf buckets create <bucket_id>zg
If the bucket is private, make sure you are authenticated and your token has the required permissions.z/
If the bucket does not exist, create it with: )	bucket_id)r   r    cmds      r"   _format_bucket_not_foundr,   @   sY    )6"5??"34!-uuC=cUCCCJr$   c                     | j                   r| j                   nd}| j                  rt        | j                  j                        nd }| j                  rd| d| j                   d}nd| d}|r|d| z  }|S )Nr&   zFile not found in r   '..z
URL: )r   responsestrurlr   )r   r   r2   r    s       r"   _format_entry_not_foundr3   L   st    $EOOLE%*^^#enn  
!C}}"5'EMM?"="5'+
Jr$   c                 2    | j                   }|d| S d|  S )NzLocal entry not found. )	__cause__)r   causes     r"   _format_local_entry_not_foundr7   X   s+    OOE(00$UG,,r$   c                 @    t        |       }|d| j                   z  }|S )Nz#
Incomplete snapshot available at: )r7   snapshot_path)r   r    s     r"   _format_incomplete_snapshotr:   _   s*    
'
.C1%2E2E1FGGCJr$   c                     | j                   r| j                   nd}| j                  rd| d| j                   dS d| dS )Nr&   zRevision not found in r   r.   z. Check the revision parameter.)r   r   r'   s     r"   _format_revision_not_foundr<   e   sC    $EOOLE}}'wbrBB#E7*IJJr$   c                     t        |       S )z%No traceback, just the error message.r1   r   s    r"   _format_cli_errorr@   l   s    u:r$   c                     | j                   Wdj                  t        j                  t	        | j                         | j                   | j                   j
                              nd}| d|  S )a0  Format a CLI extension installation error.

    The error is likely to be a tricky subprocess error to investigate. In this specific case we want to format the
    traceback of the root cause while keeping the "nicely formatted" error message of the CLIExtensionInstallError
    as a 1-line message.
    r   
)r5   join	tracebackformat_exceptiontype__traceback__)r   cause_tbs     r"   #_format_cli_extension_install_errorrI   q   s`     ??& 		**4+@%//SXSbSbSpSpqr 
 Zr%!!r$   c                     t        |       S Nr>   r?   s    r"   <lambda>rL      s
    E
 r$   c                      y)Nz)Not logged in. Run 'hf auth login' first. )_s    r"   rL   rL      s    r$   c                     d|  S )NzOIDC Exchange failed. rN   r?   s    r"   rL   rL      s    5eW= r$   c                     d|  S )NzLogin failed: rN   r?   s    r"   rL   rL      s    ^E7#; r$   c                     t        |       S rK   r>   r?   s    r"   rL   rL      s
    c%j r$   c                     t        |       S rK   r>   r?   s    r"   rL   rL      s
    #e* r$   c                 :    d| j                    d| j                   S )NzInvalid HF URI: z. )urir    r?   s    r"   rL   rL      s     02eii[I r$   c                     d|  S )NzInvalid value. rN   r?   s    r"   rL   rL      s    w7 r$   .CLI_ERROR_MAPPINGSc                 h    t         j                         D ]  \  }}t        | |      s ||       c S  y rK   )rW   items
isinstance)r   exc_type	formatters      r"   format_known_exceptionr]      s9    1779 $)eX&U##$ r$   )&__doc__rD   collections.abcr   huggingface_hub.errorsr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r1   r#   r(   r,   r3   r7   r:   r<   r@   rI   
ValueErrorrW   dictrF   	Exception__annotations__r]   rN   r$   r"   <module>re      s   $  $    ("9 c $=n = =	$7 	C 		#; 	 	-)@ -S -'> 3 K&; K KX # 
"/G "C "A2A &A 1	A
 3A 5A RA =A ;A 5A 8A :A 0A ,A  I!A" 7#A$ A%A& 'A Di(38*<<= .) d
 r$   