Repository: nvaccess/nvda

Issue:
Typing in Google Docs in Chrome with braille display connected throws errors
<!--
Please thoroughly read NVDA's wiki article on how to fill in this template, including how to provide the required files.
Issues may be closed if the required information is not present.
https://github.com/nvaccess/nvda/wiki/Github-issue-template-explanation-and-examples
-->

### Steps to reproduce:
- Connect a Braille display
- Open a file or make a new one in Google Docs
- Turn Braille Mode on in Google Docs
- Start typing
### Actual behavior:
Every few characters an error sound is triggered and the following messages get logged repeatedly:
ERROR - core.CorePump.run (12:29:04.288):
errors in this core pump cycle
Traceback (most recent call last):
  File "core.pyc", line 488, in run
  File "braille.pyc", line 2133, in pumpAll
  File "braille.pyc", line 1875, in handlePendingCaretUpdate
  File "braille.pyc", line 1881, in _doCursorMove
  File "braille.pyc", line 952, in update
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 469, in expand
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 433, in _findUnitEndpoints
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 201, in _findContentDescendant
COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None))
ERROR - core.CorePump.run (12:29:04.417):
errors in this core pump cycle
Traceback (most recent call last):
  File "core.pyc", line 488, in run
  File "braille.pyc", line 2133, in pumpAll
  File "braille.pyc", line 1875, in handlePendingCaretUpdate
  File "braille.pyc", line 1881, in _doCursorMove
  File "braille.pyc", line 960, in update
  File "braille.pyc", line 832, in _addTextWithFields
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 340, in getTextWithFields
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 289, in _getText
AttributeError: 'NoneType' object has no attribute 'obj'

### Expected behavior:
No errors
### System configuration:


#### NVDA Installed/portable/running from source:
Installed
#### NVDA version:
alpha-16164,8a7da1d4
#### Windows version:
Windows 10 build 17763.55
#### Name and version of other software in use when reproducing the issue:
Google Chrome Version 70.0.3538.67 (Official Build) (64-bit)
#### Other information about your system:

### Other questions:

#### Does the issue still occur after restarting your PC?
Yes
#### Have you tried any other versions of NVDA?
No

This Issue may be somewhat related to #8150 as both logs seem to mention the caret, difference being the errors always occur in Firefox (I was also able to reproduce them) while in Chrome they only occur with a Braille display connected.


Discussion:
@pitermach are you still having this issue in NVDA 2019.1.1? For me it does not trigger any error. In Which browser are you using google docs?
Yep, I'm still seeing this with Chrome 74 and alpha-17104,6d4b1121. I also tried with 2019.1.1, and the issue is less annoying on a stable version as it doesn't play the error sound. However if I check the log the same errors still get logged.
@pitermach could you test please with NVDA 2020.1 and Chrome 83? Is this still an issue?
Yep, this appears to still be a problem in Chrome 83 and NVDA 2020.1, with slightly different errors logged:

ERROR - core.CorePump.run (21:08:44.179) - MainThread (10616):
errors in this core pump cycle
Traceback (most recent call last):
  File "core.pyc", line 517, in run
  File "braille.pyc", line 2216, in pumpAll
  File "braille.pyc", line 1952, in handlePendingCaretUpdate
  File "braille.pyc", line 1958, in _doCursorMove
  File "braille.pyc", line 994, in update
  File "braille.pyc", line 849, in _addTextWithFields
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 342, in getTextWithFields
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 305, in _getText
IndexError: pop from empty list
ERROR - core.CorePump.run (21:08:44.395) - MainThread (10616):
errors in this core pump cycle
Traceback (most recent call last):
  File "core.pyc", line 517, in run
  File "braille.pyc", line 2216, in pumpAll
  File "braille.pyc", line 1952, in handlePendingCaretUpdate
  File "braille.pyc", line 1958, in _doCursorMove
  File "braille.pyc", line 994, in update
  File "braille.pyc", line 849, in _addTextWithFields
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 342, in getTextWithFields
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 305, in _getText
IndexError: pop from empty list
ERROR - core.CorePump.run (21:08:45.187) - MainThread (10616):
errors in this core pump cycle
Traceback (most recent call last):
  File "core.pyc", line 517, in run
  File "braille.pyc", line 2216, in pumpAll
  File "braille.pyc", line 1952, in handlePendingCaretUpdate
  File "braille.pyc", line 1958, in _doCursorMove
  File "braille.pyc", line 994, in update
  File "braille.pyc", line 849, in _addTextWithFields
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 342, in getTextWithFields
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 290, in _getText
AttributeError: 'NoneType' object has no attribute 'obj'
ERROR - core.CorePump.run (21:08:45.400) - MainThread (10616):
errors in this core pump cycle
Traceback (most recent call last):
  File "core.pyc", line 517, in run
  File "braille.pyc", line 2216, in pumpAll
  File "braille.pyc", line 1952, in handlePendingCaretUpdate
  File "braille.pyc", line 1958, in _doCursorMove
  File "braille.pyc", line 1011, in update
  File "braille.pyc", line 849, in _addTextWithFields
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 342, in getTextWithFields
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 290, in _getText
AttributeError: 'NoneType' object has no attribute 'obj'
ERROR - core.CorePump.run (21:08:45.712) - MainThread (10616):
errors in this core pump cycle
Traceback (most recent call last):
  File "core.pyc", line 517, in run
  File "braille.pyc", line 2216, in pumpAll
  File "braille.pyc", line 1952, in handlePendingCaretUpdate
  File "braille.pyc", line 1958, in _doCursorMove
  File "braille.pyc", line 994, in update
  File "braille.pyc", line 849, in _addTextWithFields
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 342, in getTextWithFields
  File "NVDAObjects\IAccessible\ia2TextMozilla.pyc", line 290, in _getText
AttributeError: 'NoneType' object has no attribute 'obj'

`IndexError: pop from empty list` is being handled in issue #10619 PR #11318.

For `AttributeError: 'NoneType' object has no attribute 'obj'`, there's also #5454.

Resolving patch:
diff --git a/source/NVDAObjects/IAccessible/ia2TextMozilla.py b/source/NVDAObjects/IAccessible/ia2TextMozilla.py
--- a/source/NVDAObjects/IAccessible/ia2TextMozilla.py
+++ b/source/NVDAObjects/IAccessible/ia2TextMozilla.py
@@ -170,8 +170,12 @@ def _makeRawTextInfo(self, obj, position):
 		return _getRawTextInfo(obj)(obj, position)
 
 	def _getEmbedding(self, obj):
+		parent = obj.parent
+		if not parent:
+			# obj is probably dead.
+			return None
 		# optimisation: Passing an Offsets position checks nCharacters, which is an extra call we don't need.
-		info = self._makeRawTextInfo(obj.parent, textInfos.POSITION_FIRST)
+		info = self._makeRawTextInfo(parent, textInfos.POSITION_FIRST)
 		if isinstance(info, FakeEmbeddingTextInfo):
 			info._startOffset = obj.indexInParent
 			info._endOffset = info._startOffset + 1
@@ -294,6 +298,12 @@ def _getText(self, withFields, formatConfig=None):
 					fields.insert(0, textInfos.FieldCommand("controlStart", field))
 				controlStack.insert(0, field)
 				ti = self._getEmbedding(obj)
+				if not ti:
+					log.debugWarning(
+						"_getEmbedding returned None while getting initial fields. "
+						"Object probably dead."
+					)
+					return []
 				obj = ti.obj
 		else:
 			controlStack = None
@@ -323,6 +333,12 @@ def _getText(self, withFields, formatConfig=None):
 					field["_endOfNode"] = True
 					fields.append(textInfos.FieldCommand("controlEnd", None))
 			ti = self._getEmbedding(obj)
+			if not ti:
+				log.debugWarning(
+					"_getEmbedding returned None while ascending to get more text. "
+					"Object probably dead."
+				)
+				return []
 			obj = ti.obj
 			if ti.move(textInfos.UNIT_OFFSET, 1) == 0:
 				# There's no more text in this object.


Test patch: