fix: guard against None control in ControlPhotographer.capture#323
Open
nuthalapativarun wants to merge 1 commit intomicrosoft:pre-releasefrom
Open
fix: guard against None control in ControlPhotographer.capture#323nuthalapativarun wants to merge 1 commit intomicrosoft:pre-releasefrom
nuthalapativarun wants to merge 1 commit intomicrosoft:pre-releasefrom
Conversation
When the application window becomes unavailable (e.g. it closes between the screenshot request and the actual capture), the control element passed to ControlPhotographer can be None. Calling .capture_as_image() on None raises: AttributeError: 'NoneType' object has no attribute 'capture_as_image' Add an explicit None-check that logs a warning and returns None, letting callers handle the missing screenshot gracefully instead of crashing. Closes microsoft#232
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.
Summary
When an application window closes or becomes unavailable between the time it is identified and the screenshot capture step, the
UIAWrappercontrol element can beNone. Calling.capture_as_image()on aNoneobject raises:This crash surfaces in the
AppAgentscreenshot step and terminates the agent loop unexpectedly.Changes
Noneguard at the top ofControlPhotographer.capture()inufo/automator/ui_control/screenshot.pyNonewhen the control is unavailable, allowing callers to handle the missing screenshot gracefullyTesting
The fix follows the existing pattern used throughout the codebase (
if save_path is not None and screenshot is not None) and is consistent with theDesktopPhotographerand other photographer variants which already returnNoneon failure.Closes #232