Skip to content

Commit

Permalink
Catch Xlib.error.DisplayConnectionError from mouseinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Aug 18, 2024
1 parent b4255d0 commit 7adf261
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pyautogui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,20 @@ def mouseInfo():
"""
mouseinfo.MouseInfoWindow()

except ImportError:

except Exception as exception:
_mouseInfoExceptionMessage = "PyAutoGUI was unable to import mouseinfo"
if isinstance(exception, ImportError):
_mouseInfoExceptionMessage += ". Please install this module to enable the function you tried to call."
else:
_mouseInfoExceptionMessage += f" because of the following exception: {exception}"

def mouseInfo():
"""
This function raises PyAutoGUIException. It's used for the MouseInfo function names if the MouseInfo module
failed to be imported.
"""
raise PyAutoGUIException(
"PyAutoGUI was unable to import mouseinfo. Please install this module to enable the function you tried to call."
)
raise PyAutoGUIException(_mouseInfoExceptionMessage)


def useImageNotFoundException(value=None):
Expand Down

0 comments on commit 7adf261

Please sign in to comment.