Skip to content

Better error message if invalid token on whoami #2809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Wauplin opened this issue Jan 30, 2025 · 0 comments · Fixed by #2814
Closed

Better error message if invalid token on whoami #2809

Wauplin opened this issue Jan 30, 2025 · 0 comments · Fixed by #2814
Labels
good first issue Good for newcomers

Comments

@Wauplin
Copy link
Contributor

Wauplin commented Jan 30, 2025

In HfApi.whoami, we raise a custom error if token is invalid:

                "Invalid user token. If you didn't pass a user token, make sure you "
                "are properly logged in by executing `huggingface-cli login`, and "
                "if you did pass a user token, double-check it's correct."

It would be great to customize the error message depending on the user case. Especially depending on if:

  • token comes from input parameter
  • token comes from HF_TOKEN env variable
  • token comes from ~/.cache/huggingface/token local file
  • token comes from Google Colab vault

Current error hides this to the user which can be frustrating. Typically if an outdated HF_TOKEN env variable is set and user has logged in using huggingface-cli login (i.e. saving token to a file), the env variable will still take precedence. A better error message would be less confusing in that case.

See

"Invalid user token. If you didn't pass a user token, make sure you "

(quickly discussed it on private slack)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant