diff --git a/source/speech/manager.py b/source/speech/manager.py index ea4d72a2b8f..b74da7d081f 100644 --- a/source/speech/manager.py +++ b/source/speech/manager.py @@ -466,12 +466,21 @@ def _buildNextUtterance(self): utterance.extend(seq) lastSequenceIndexAddedToUtterance = seqIndex # if any items are cancelled, cancel the whole utterance. - if utterance and not self._checkForCancellations(utterance): - log.error(f"Checking for cancellations failed, cancelling sequence: {utterance}") + try: + utteranceValid = len(utterance) == 0 or self._checkForCancellations(utterance) + except IndexError: + log.error( + f"Checking for cancellations failed, cancelling sequence: {utterance}", + exc_info=True + ) # Avoid infinite recursion by removing the problematic sequences: del self._curPriQueue.pendingSequences[:lastSequenceIndexAddedToUtterance + 1] + utteranceValid = False + + if utteranceValid: + return utterance + else: return self._buildNextUtterance() - return utterance def _checkForCancellations(self, utterance: SpeechSequence) -> bool: """ @@ -485,8 +494,9 @@ def _checkForCancellations(self, utterance: SpeechSequence) -> bool: return True utteranceIndex = self._getUtteranceIndex(utterance) if utteranceIndex is None: - log.error("no utterance index, cant save cancellable commands") - return False + raise IndexError( + f"no utterance index({utteranceIndex}, cant save cancellable commands" + ) cancellableItems = list( item for item in reversed(utterance) if isinstance(item, _CancellableSpeechCommand) )