Repository: nvaccess/nvda

Issue:
Errors when navigating in and out of some edit fields
<!-- Please read the text in this edit field before filling it in.
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/blob/master/devDocs/githubIssueTemplateExplanationAndExamples.md
Please also note that the NVDA project has a Citizen and Contributor Code of Conduct which can be found at https://github.com/nvaccess/nvda/blob/master/CODE_OF_CONDUCT.md. NV Access expects that all contributors and other community members read and abide by the rules set out in this document while participating or contributing to this project. This includes creating or commenting on issues and pull requests. 

Each of the questions and sections below start with multiple hash symbols (#). Place your answers and information on the blank line below each question.
-->

### Steps to reproduce:
This seems to happen in any UIA edit field. I've seen this in Unigram, but it occurs in other places as well.
1. Go into an edit field that causes the issue, and tab or otherwise navigate out of it.
### Actual behavior:
An error is reported in the log.
### Expected behavior:
No error.
### System configuration
#### NVDA installed/portable/running from source:
Installed
#### NVDA version:
alpha-23940,c6aa7712
#### Windows version:
Windows 11, build 22471.
#### Name and version of other software in use when reproducing the issue:
Unigram 8.1.6643.0.
#### Other information about your system:
N/A
### Other questions
#### Does the issue still occur after restarting your computer?
Yes
#### Have you tried any other versions of NVDA? If so, please report their behaviors.
Yes, alpha-23903,fb4466ee works normally. This seems to have introduced some time around alpha-23913,cfeb3d27.
#### If NVDA add-ons are disabled, is your problem still occurring?
Yes.
#### Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?
Yes.
Debug log fragment.
Input: kb(laptop):tab
IO - speech.speech.speak (09:37:02.432) - MainThread (8220):
Speaking [LangChangeCommand ('en_US'), 'Attach media', 'button', CancellableSpeech (still valid)]
ERROR - queueHandler.flushQueue (09:37:02.464) - MainThread (8220):
Error in func NVDAObject._reportErrorInPreviousWord.<locals>._delayedDetection
Traceback (most recent call last):
  File "queueHandler.pyc", line 55, in flushQueue
  File "NVDAObjects\__init__.pyc", line 1067, in _delayedDetection
  File "NVDAObjects\UIA\__init__.pyc", line 764, in getTextWithFields
AttributeError: 'NoneType' object has no attribute 'UIAElement'


Discussion:
Hi, looks like a regression from spelling error detection in Word. CC @MichaelDCurran


I've experienced something similar when tabbing in Firefox's profile selection dialog:
```
ERROR - queueHandler.flushQueue (18:07:01.213) - MainThread (3880):
Error in func NVDAObject._reportErrorInPreviousWord.<locals>._delayedDetection
Traceback (most recent call last):
  File "queueHandler.pyc", line 55, in flushQueue
  File "NVDAObjects\__init__.pyc", line 1067, in _delayedDetection
  File "textInfos\offsets.pyc", line 573, in getTextWithFields
  File "NVDAObjects\IAccessible\__init__.pyc", line 241, in _getFormatFieldAndOffsets
AttributeError: 'NoneType' object has no attribute 'IAccessibleTextObject'
```

Resolving patch:
diff --git a/source/NVDAObjects/__init__.py b/source/NVDAObjects/__init__.py
--- a/source/NVDAObjects/__init__.py
+++ b/source/NVDAObjects/__init__.py
@@ -1065,7 +1065,7 @@ def _reportErrorInPreviousWord(self):
 		def _delayedDetection():
 			try:
 				fields = info.getTextWithFields()
-			except RuntimeError:
+			except Exception:
 				log.debugWarning("Error fetching formatting for last character of previous word", exc_info=True)
 				return
 			for command in fields:


Test patch: