Skip to content

fix: guard against None control in ControlPhotographer.capture#323

Open
nuthalapativarun wants to merge 1 commit intomicrosoft:pre-releasefrom
nuthalapativarun:fix/capture-as-image-none-control
Open

fix: guard against None control in ControlPhotographer.capture#323
nuthalapativarun wants to merge 1 commit intomicrosoft:pre-releasefrom
nuthalapativarun:fix/capture-as-image-none-control

Conversation

@nuthalapativarun
Copy link
Copy Markdown

Summary

When an application window closes or becomes unavailable between the time it is identified and the screenshot capture step, the UIAWrapper control element can be None. Calling .capture_as_image() on a None object raises:

AttributeError: 'NoneType' object has no attribute 'capture_as_image'

This crash surfaces in the AppAgent screenshot step and terminates the agent loop unexpectedly.

Changes

  • Added a None guard at the top of ControlPhotographer.capture() in ufo/automator/ui_control/screenshot.py
  • Logs a warning and returns None when the control is unavailable, allowing callers to handle the missing screenshot gracefully

Testing

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 the DesktopPhotographer and other photographer variants which already return None on failure.

Closes #232

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
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.

1 participant