Skip to content

j commands exception handling edge cases#339

Merged
mangelajo merged 1 commit into
jumpstarter-dev:mainfrom
bkhizgiy:exp_follow
Mar 18, 2026
Merged

j commands exception handling edge cases#339
mangelajo merged 1 commit into
jumpstarter-dev:mainfrom
bkhizgiy:exp_follow

Conversation

@bkhizgiy
Copy link
Copy Markdown
Member

No description provided.

Handle Ctrl+C consistently in the reauthentication wrapper, simplify timeout type checks, and add direct login config fetch tests so timeout/JSON mapping behavior is actually exercised.

Assisted-by: GPT-5.3 Codex
Signed-off-by: Bella Khizgiyaev <bkhizgiy@redhat.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 18, 2026

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit db6f207
🔍 Latest deploy log https://app.netlify.com/projects/jumpstarter-docs/deploys/69bab29da359f50008a66dea
😎 Deploy Preview https://deploy-preview-339--jumpstarter-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 18, 2026

📝 Walkthrough

Walkthrough

The changes enhance exception handling in the CLI common package by removing obsolete asyncio imports, standardizing timeout error handling to use TimeoutError, and adding explicit KeyboardInterrupt mapping to CLI-friendly exceptions. Corresponding tests verify the new exception mapping behavior for interrupts, timeouts, and JSON decode errors.

Changes

Cohort / File(s) Summary
Exception handling updates
python/packages/jumpstarter-cli-common/jumpstarter_cli_common/exceptions.py
Removed asyncio import and FutureTimeoutError alias. Updated _map_runtime_exception to treat timeouts uniformly as TimeoutError with updated hint messaging. Added explicit KeyboardInterrupt handling in both async_handle_exceptions and handle_exceptions to map user cancellations to ClickException or re-raise.
Exception mapping tests
python/packages/jumpstarter-cli-common/jumpstarter_cli_common/exceptions_test.py, python/packages/jumpstarter-cli/jumpstarter_cli/login_test.py
Added test for KeyboardInterrupt mapping in reauthentication context. Added tests for fetch_auth_config timeout and JSON decode error handling, verifying exception-to-ClickException mappings work correctly in login flow.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 When fingers press Ctrl+C with haste,
No more shall the rabbit panic or taste,
The bitter TimeoutError's sting,
For KeyboardInterrupt's now a gentler thing—
Mapped kindly to "Cancelled," no race.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No description was provided by the author, making it impossible to assess relevance to the changeset. Add a pull request description explaining the exception handling improvements, the specific edge cases addressed (KeyboardInterrupt, TimeoutError), and the rationale for these changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'j commands exception handling edge cases' clearly summarizes the main changes, which involve improving exception handling for edge cases like KeyboardInterrupt and TimeoutError across multiple files in the CLI.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
python/packages/jumpstarter-cli-common/jumpstarter_cli_common/exceptions.py (1)

207-213: ⚠️ Potential issue | 🟡 Minor

Handle KeyboardInterrupt inside login_func() at the reauthentication point.

When login_func(config) is called on line 212 from inside _handle_connection_error_with_reauth(), a KeyboardInterrupt raised during re-auth will not be caught by the sibling handler on line 251. This occurs because exceptions raised within an except block are not caught by sibling except handlers at the same try/except level—only by outer ones. The verification confirms this behavior:

# KeyboardInterrupt raised inside except suite bypasses sibling handler
try:
    try:
        raise Exception("expired token")
    except Exception:
        raise KeyboardInterrupt()  # Raised here
    except KeyboardInterrupt:
        print("mapped")  # This line is never reached
except BaseException as exc:
    print(type(exc).__name__)  # Prints: KeyboardInterrupt

This means KeyboardInterrupt during login will propagate uncaught instead of being mapped to ClickExceptionRed("Cancelled by user").

Suggested fix

Wrap the login_func() call in its own try/except handler:

 def _handle_connection_error_with_reauth(exc, login_func):
     """Handle ConnectionError with reauthentication logic."""
     if "expired" in str(exc).lower():
         click.echo(click.style("Token is expired, triggering re-authentication", fg="red"))
         config = exc.get_config()
-        login_func(config)
+        try:
+            login_func(config)
+        except KeyboardInterrupt as interrupt:
+            if cli_exc := _map_cli_exception(interrupt):
+                raise cli_exc from None
+            raise
         raise ClickExceptionRed("Please try again now") from None
     else:
         raise ClickExceptionRed(str(exc)) from None
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@python/packages/jumpstarter-cli-common/jumpstarter_cli_common/exceptions.py`
around lines 207 - 213, In _handle_connection_error_with_reauth, wrap the call
to login_func(config) in a try/except that catches KeyboardInterrupt and raises
ClickExceptionRed("Cancelled by user") from None so a user-cancel during reauth
is mapped correctly; keep the existing flow that raises
ClickExceptionRed("Please try again now") on successful reauth and let other
exceptions propagate unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@python/packages/jumpstarter-cli-common/jumpstarter_cli_common/exceptions.py`:
- Around line 207-213: In _handle_connection_error_with_reauth, wrap the call to
login_func(config) in a try/except that catches KeyboardInterrupt and raises
ClickExceptionRed("Cancelled by user") from None so a user-cancel during reauth
is mapped correctly; keep the existing flow that raises
ClickExceptionRed("Please try again now") on successful reauth and let other
exceptions propagate unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 84a18029-d2f8-4d08-b81e-02172ec7608a

📥 Commits

Reviewing files that changed from the base of the PR and between c6cf780 and db6f207.

📒 Files selected for processing (3)
  • python/packages/jumpstarter-cli-common/jumpstarter_cli_common/exceptions.py
  • python/packages/jumpstarter-cli-common/jumpstarter_cli_common/exceptions_test.py
  • python/packages/jumpstarter-cli/jumpstarter_cli/login_test.py

@mangelajo mangelajo enabled auto-merge (squash) March 18, 2026 14:29
@mangelajo mangelajo merged commit 4647f1d into jumpstarter-dev:main Mar 18, 2026
31 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.

2 participants