Skip to content

Commit

Permalink
Prevent an uninitialized ScriptableObject from breaking script handli…
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienCochuyt committed May 14, 2020
1 parent dba3343 commit 11268dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
15 changes: 10 additions & 5 deletions source/baseObject.py
@@ -1,8 +1,7 @@
#baseObject.py
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2007-2018 NV Access Limited, Christopher Toth, Babbage B.V.
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2007-2020 NV Access Limited, Christopher Toth, Babbage B.V., Julien Cochuyt
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.

"""Contains the base classes that many of NVDA's classes such as NVDAObjects, virtualBuffers, appModules, synthDrivers inherit from. These base classes provide such things as auto properties, and methods and properties for scripting and key binding.
"""
Expand Down Expand Up @@ -283,6 +282,12 @@ def getScript(self,gesture):
return self._gestureMap[identifier].__get__(self, self.__class__)
except KeyError:
continue
except AttributeError:
log.exception((
"Did you miss to initialize the base class?"
f"\nMRO={self.__class__.__mro__}"
) if not hasattr(self, "_gestureMap") else None)
return None
else:
return None

Expand Down
9 changes: 6 additions & 3 deletions source/scriptHandler.py
@@ -1,6 +1,6 @@
# scriptHandler.py
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2007-2019 NV Access Limited, Babbage B.V.
# Copyright (C) 2007-2020 NV Access Limited, Babbage B.V., Julien Cochuyt
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.

Expand Down Expand Up @@ -54,8 +54,11 @@ def _getObjScript(obj, gesture, globalMapScripts):
except AttributeError:
pass

# Search the object itself for in-built bindings.
return obj.getScript(gesture)
try:
# Search the object itself for in-built bindings.
return obj.getScript(gesture)
except: # noqa: E722 do not use bare 'except'
log.exception()

def findScript(gesture):
focus = api.getFocusObject()
Expand Down

0 comments on commit 11268dc

Please sign in to comment.