Repository: nvaccess/nvda

Issue:
2019.3 beta 1 logs this error semi-frequently
<!--
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:
not known

### Actual behavior:
Nothing odd happens, except the two-note sound indicating an error. Each time I check the log, I find the same traceback. Here it is:

```
ERROR - core.CorePump.run (08:48:53.754) - MainThread (9024):
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 305, in _getText
IndexError: pop from empty list
```
### Expected behavior:
n/a
### System configuration
#### NVDA installed/portable/running from source:
portable
#### NVDA version:
2019.3 beta 1
#### Windows version:
10, 1903
#### Name and version of other software in use when reproducing the issue:
no specific software seems to trigger the problem
#### Other information about your system:
n/a
### Other questions
#### Does the issue still occur after restarting your PC?
yes
#### Have you tried any other versions of NVDA? If so, please report their behaviors.
new in this beta as far as I can tell, though I don't often read the log on non-beta versions


Discussion:
Reminds me of the way the suggest number of items in a list often gets it 
wrong.
> Reminds me of the way the suggest number of items in a list often gets it wrong.

That's entirely unrelated.

According to the log, it looks like you were using Firefox or Thunderbird when triggering this problem. Do you use one or both of those?
Maybe related: Issue #8967

@mehgcap: I guess if you have disabled the braille output (= no braille display), then this error doesn't occur, right?
Yes, I was using Firefox. I thought I noticed it happening in other apps as well, though I could be wrong.

Yes, if no braille display is in use, the error goes away.
cc: @MarcoZehe 
I expect this is a quick fix, though I haven't investigated. Since it is not causing any noticeable bad behavior, it won't get fixed for 2019.3
@feerrenrut May I ask why this one has been assigned a P1? It seems it only causes error sound to be played and there is no noticeable bad behavior for the user.
I've thought that P1 is reserved for severe crashes of either NVDA or other programs when accessed with it.
Because I suspect its a quick fix, and until investigated it's hard to be sure that it isn't causing hard to detect problems.
@mehgcap are you still seeing this error in NVDA 2020.1 with Firefox 76? Please also try to run the COM resgistration fixing tool in NVDA menu / tools and see if the error occurs after that. Please report your results here. Thanks.


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
@@ -18,6 +18,7 @@
 from . import IA2TextTextInfo, IAccessible
 from compoundDocuments import CompoundTextInfo
 import locationHelper
+from logHandler import log
 
 class FakeEmbeddingTextInfo(textInfos.offsets.OffsetsTextInfo):
 	encoding = None
@@ -308,7 +309,15 @@ def _getText(self, withFields, formatConfig=None):
 			# The end hasn't yet been reached, which means it isn't a descendant of obj.
 			# Therefore, continue from where obj was embedded.
 			if withFields:
-				field = controlStack.pop()
+				try:
+					field = controlStack.pop()
+				except IndexError:
+					# We're trying to walk up past our root. This can happen if a descendant
+					# object within the range died, in which case _iterRecursiveText will
+					# never reach our end object and thus won't yield None. This means this
+					# range is invalid, so just return nothing.
+					log.debugWarning("Tried to walk up past the root. Objects probably dead.")
+					return []
 				if field:
 					# This object had a control field.
 					field["_endOfNode"] = True


Test patch: