From e240b4e89d22f2e8814ecff6eec838e2feda06c2 Mon Sep 17 00:00:00 2001 From: Yi-111-a <153097222+Yi-111-a@users.noreply.github.com> Date: Tue, 3 Nov 2026 17:16:09 +0800 Subject: [PATCH] fix: only cache the HF token after whoami validation --- src/heretic/main.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/heretic/main.py b/src/heretic/main.py index 068b585..14a47ab 100644 --- a/src/heretic/main.py +++ b/src/heretic/main.py @@ -1009,12 +1009,17 @@ def run(): if not token: continue - # Remember the token so that a subsequent upload in the same - # session does not prompt for it again. It is intentionally kept - # out of `settings`, and is never persisted to disk. - upload_token = token + # Validate the token before remembering it, so that a mistyped + # token does not stay cached for the rest of the session. + try: + user = huggingface_hub.whoami(token) + except Exception: + # Clear any cached token so the next upload attempt prompts + # for a replacement. It is intentionally kept out of + # `settings`, and is never persisted to disk. + upload_token = None + raise - user = huggingface_hub.whoami(token) fullname = user.get( "fullname", user.get("name", "unknown user"),