Skip to content

fix(cli): handle config auth failures without traceback spam#1080

Merged
SaboniAmine merged 1 commit intomlco2:masterfrom
LarytheLord:fix/cli-config-clean-error-855
Feb 26, 2026
Merged

fix(cli): handle config auth failures without traceback spam#1080
SaboniAmine merged 1 commit intomlco2:masterfrom
LarytheLord:fix/cli-config-clean-error-855

Conversation

@LarytheLord
Copy link
Contributor

Summary

Fixes noisy CLI behavior in codecarbon config when an existing login token is expired/invalid.

Previously, show_config() called get_access_token() before entering its try block, so auth/refresh errors escaped and triggered a long traceback. This made the config wizard hard to use for simple re-auth flows.

This PR:

  • moves API/token validation inside the guarded block in show_config()
  • replaces exception re-raise with a concise warning message
  • keeps the wizard flow running so users can continue local config setup

Fixes #855.

Tests

  • Added test_show_config_handles_access_token_errors in tests/cli/test_cli_main.py.
  • Local validation:
    • uv run pytest tests/cli/test_cli_main.py -k "show_config_handles_access_token_errors or test_api_get_calls_api_and_prints"
    • uv run ruff check codecarbon/cli/main.py tests/cli/test_cli_main.py

@LarytheLord LarytheLord requested a review from a team as a code owner February 26, 2026 09:16
Copy link
Member

@SaboniAmine SaboniAmine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your contribution!

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.19%. Comparing base (b370a5a) to head (d9d6d50).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1080      +/-   ##
==========================================
+ Coverage   78.14%   78.19%   +0.05%     
==========================================
  Files          38       38              
  Lines        3637     3637              
==========================================
+ Hits         2842     2844       +2     
+ Misses        795      793       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SaboniAmine SaboniAmine merged commit 521adc8 into mlco2:master Feb 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CLI] Many error message when running "codecarbon config"

2 participants