refactor(macos): dedupe the cancellable fail-soft pattern in present/_present_status - #378
Merged
Merged
Conversation
…_present_status
present and _present_status each wrapped their body in the identical
except asyncio.CancelledError: raise / except Exception as error: await
self._degrade(f"presentation_failed:{type(error).__name__}", error) shape.
Extract a shared _fail_soft_cancellable decorator (the cancellation-aware
counterpart to the existing _fail_soft decorator from #373) so both methods
keep only their distinct dispatch bodies.
No behavior change: the try/except previously wrapped the code below the
early-return guards in present, and those guards cannot raise, so moving
them inside the decorated body is equivalent. Full suite (914 passed / 3
skipped / 1 deselected) and ruff check/format pass unmodified.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NoGweAuMDdcoLXYHWgfY3j
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
MacOSPresentationController.presentand_present_status(yutori/navigator/macos/presentation.py) each wrapped their dispatch body in the identicalblock. This is the same duplication class the
_fail_softdecorator (#373) already consolidated forshow_thumbnail/before_capture/after_capture/encode_observation— those four methods explicitly couldn't reuse_fail_softbecause they need to reraiseCancelledErrorbefore degrading, so the pattern was left duplicated in these two methods instead.Improvement
Extracted a new
_fail_soft_cancellabledecorator — the cancellation-aware counterpart to_fail_soft— and applied it to bothpresentand_present_status. Each method now keeps only its distinct dispatch body.Why it's safe
trypreviously wrapped only the code below each method's early-return guards (e.g.if not self._status.available or self._stopping: return); those guards are simple attribute checks that cannot raise, so moving them inside the decorated body is equivalent. The exception handling order (reraiseCancelledError, else degrade with the samef"presentation_failed:{type(error).__name__}"reason) is byte-for-byte preserved.914 passed, 3 skipped, 1 deselected(same as baseline).ruff checkandruff format --checkboth clean on the touched file.Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
🤖 Generated with Claude Code
https://claude.ai/code/session_01NoGweAuMDdcoLXYHWgfY3j
Generated by Claude Code
Note
Low Risk
Mechanical refactor in internal macOS presentation error handling with preserved cancellation and degrade semantics; no API or logic changes described.
Overview
Introduces
_fail_soft_cancellable, a decorator that re-raisesasyncio.CancelledErrorand otherwise degrades with the samepresentation_failed:{exception}reason used before, matching the cancellation-aware branch that was duplicated onpresentand_present_status.Both methods drop their inline
try/exceptblocks and are annotated with the new decorator so only event-dispatch logic remains. The_fail_softdocstring now points readers at_fail_soft_cancellablefor methods that must not treat cancellation as a presentation failure.No intended behavior change—exception order and degrade messaging are preserved; early-return guards now run inside the decorated wrapper (still safe for the existing guard checks).
Reviewed by Cursor Bugbot for commit 86b132d. Bugbot is set up for automated code reviews on this repo. Configure here.