Skip to content

fix(cli): abort config wizard cleanly when a selection is cancelled - #1473

Merged
benoit-cty merged 1 commit into
mlco2:masterfrom
nel507:fix-cli-cancel-prompt
Nov 1, 2026
Merged

benoit-cty merged 1 commit into
mlco2:masterfrom
nel507:fix-cli-cancel-prompt

Conversation

@nel507

@nel507 nel507 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Description

questionary_prompt now raises typer.Abort() when the selection is None, so the codecarbon config wizard exits cleanly with "Aborted." when the user cancels, like the other Typer prompts do.

Related Issue

No existing issue; found while trying the CLI during Hacktoberfest Hack Day Panama City.

Motivation and Context

In codecarbon config, pressing Ctrl+C on a selection menu makes questionary return None. The wizard keeps going and crashes with Error: list index out of range. On the first menu ("Use existing global config…"), cancelling silently creates a new config file instead of stopping.

How Has This Been Tested?

  • Reproduced the crash by simulating a cancelled questionary.select(...).ask() (returns None) through CliRunner: before the fix → IndexError; after → "Aborted." with exit code 1.
  • Added test_questionary_prompt_aborts_when_cancelled in tests/cli/test_cli.py.
  • pytest tests/cli/ → all tests pass. ruff format --check passes on the changed files.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

AI Usage Disclosure

  • 🟥 AI-vibecoded
  • 🟠 AI-generated: the bug was found and the fix and test were written with an AI assistant; I reviewed the change and can explain it.
  • ⭐ AI-assisted
  • ♻️ No AI used

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the docs/how-to/contributing.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@nel507
nel507 requested a review from a team as a code owner October 31, 2026 17:14
@benoit-cty
benoit-cty force-pushed the fix-cli-cancel-prompt branch from cdf29a2 to b15d338 Compare November 1, 2026 13:43

@benoit-cty benoit-cty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for reporting and fixing this.

I hope your HacktoberFest goes well !

@benoit-cty
benoit-cty enabled auto-merge November 1, 2026 13:45
@benoit-cty
benoit-cty merged commit 7ef62bf into mlco2:master Nov 1, 2026
12 checks passed
@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.67%. Comparing base (14407e4) to head (b15d338).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1473   +/-   ##
=======================================
  Coverage   93.66%   93.67%           
=======================================
  Files          50       50           
  Lines        5591     5593    +2     
=======================================
+ Hits         5237     5239    +2     
  Misses        354      354           

☔ View full report in Codecov by Harness.
📢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants