client: attach config to exception#256
Conversation
client config was not attached to the exception when token was expired, while connection errors did. this patch introduces a helper to attach the config to the exceptions when possible Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com> Assited-by: cursor auto
📝 WalkthroughWalkthroughThis change refactors token expiry error handling by extracting inlined logic into two reusable helper functions in the config client module, which are then used by the shell module to consolidate error handling. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
python/packages/jumpstarter/jumpstarter/config/client.py (1)
53-63: Consider extracting"token is expired"to a module-level constant.The same literal is used in both
_attach_config_if_expired_token(detection, line 55) andraise_expired_token_error(construction, line 61). If either string drifts they'll silently decouple — the helper will stop recognising errors raised by its sibling.♻️ Proposed refactor
+_TOKEN_EXPIRED_MSG = "token is expired" + def _attach_config_if_expired_token(exc: ConnectionError, config: ClientConfigV1Alpha1) -> None: """Attach config to a ConnectionError so re-auth can use it. No-op if not token-expired.""" - if "token is expired" in str(exc): + if _TOKEN_EXPIRED_MSG in str(exc): exc.set_config(config) def raise_expired_token_error(config: ClientConfigV1Alpha1) -> NoReturn: """Raise ConnectionError for expired token with config attached so re-auth can run.""" - err = ConnectionError("token is expired") + err = ConnectionError(_TOKEN_EXPIRED_MSG) err.set_config(config) raise err🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@python/packages/jumpstarter/jumpstarter/config/client.py` around lines 53 - 63, The literal "token is expired" is duplicated between _attach_config_if_expired_token and raise_expired_token_error; extract it to a module-level constant (e.g., TOKEN_EXPIRED_MESSAGE = "token is expired") and use that constant in both functions (replace the string check in _attach_config_if_expired_token and the constructor call in raise_expired_token_error) so detection and construction stay in sync.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@python/packages/jumpstarter/jumpstarter/config/client.py`:
- Around line 53-63: The literal "token is expired" is duplicated between
_attach_config_if_expired_token and raise_expired_token_error; extract it to a
module-level constant (e.g., TOKEN_EXPIRED_MESSAGE = "token is expired") and use
that constant in both functions (replace the string check in
_attach_config_if_expired_token and the constructor call in
raise_expired_token_error) so detection and construction stay in sync.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
python/packages/jumpstarter-cli/jumpstarter_cli/shell.pypython/packages/jumpstarter/jumpstarter/config/client.py
|
just checked the fix - it worked, but i'm seeing a warning just as the shell starts which wasn't there prior to the fix edit: nop, my main was few commits old. fetched the latest and the warning is already there as well. so not your regression. your fix LGTM |
|
warning is actually from #247 😅 |
|
right, just seen it there lol |
|
so wdyt should I open an issue for that one? seeing it in every session like that is far from ideal 🤔 |
yeah, at the time we weren't sure why all of these were suppressed (now we know) |
client config was not attached to the exception when token was expired, while connection errors did.
this patch introduces a helper to attach the config to the exceptions when possible
Summary by CodeRabbit