Skip to content

Commit 1b3c3c9

Browse files
committed
Change from using log.error() to using log.exception() so there is a stack trace.
1 parent e1a6927 commit 1b3c3c9

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

addon/globalPlugins/MathCAT/MathCAT.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def getLanguageToUse(mathMl: str = "") -> str:
8989
# ignore regional differences if the MathCAT language setting doesn't have it.
9090
mathCATLanguageSetting = libmathcat.GetPreference("Language")
9191
except Exception as e:
92-
log.error(e)
92+
log.exception(e)
9393

9494
# log.info(f"getLanguageToUse: {mathCATLanguageSetting}")
9595
if mathCATLanguageSetting != "Auto":
@@ -118,7 +118,7 @@ def ConvertSSMLTextForNVDA(text: str) -> list:
118118
try:
119119
mathCATLanguageSetting = libmathcat.GetPreference("Language")
120120
except Exception as e:
121-
log.error(e)
121+
log.exception(e)
122122
language = getLanguageToUse()
123123
nvdaLanguage = getCurrentLanguage().replace("_", "-")
124124
# log.info(f"mathCATLanguageSetting={mathCATLanguageSetting}, lang={language}, NVDA={nvdaLanguage}")
@@ -147,7 +147,7 @@ def ConvertSSMLTextForNVDA(text: str) -> list:
147147
try:
148148
libmathcat.SetPreference("Language", language)
149149
except Exception as e:
150-
log.error(e)
150+
log.exception(e)
151151
language = mathCATLanguageSetting # didn't set the language
152152
if language != nvdaLanguage:
153153
out.append(LangChangeCommand(language))
@@ -195,7 +195,7 @@ def ConvertSSMLTextForNVDA(text: str) -> list:
195195
try:
196196
libmathcat.SetPreference("Language", mathCATLanguageSetting)
197197
except Exception as e:
198-
log.error(e)
198+
log.exception(e)
199199
if language != nvdaLanguage:
200200
out.append(LangChangeCommand(None))
201201
# log.info(f"Speech commands: '{out}'")
@@ -226,7 +226,7 @@ def reportFocus(self):
226226
text = libmathcat.DoNavigateCommand("ZoomIn")
227227
speech.speak(ConvertSSMLTextForNVDA(text))
228228
except Exception as e:
229-
log.error(e)
229+
log.exception(e)
230230
# Translators: this message directs users to look in the log file
231231
speech.speakMessage(_("Error in starting navigation of math: see NVDA error log for details"))
232232

@@ -239,7 +239,7 @@ def getBrailleRegions(self, review: bool = False):
239239
try:
240240
region.rawText = libmathcat.GetBraille("")
241241
except Exception as e:
242-
log.error(e)
242+
log.exception(e)
243243
# Translators: this message directs users to look in the log file
244244
speech.speakMessage(_("Error in brailling math: see NVDA error log for details"))
245245
region.rawText = ""
@@ -294,7 +294,7 @@ def script_navigate(self, gesture: KeyboardInputGesture):
294294
# log.info(f"Navigate speech for {gesture.vkCode}/(s={'shift' in modNames}, c={'control' in modNames}): '{text}'")
295295
speech.speak(ConvertSSMLTextForNVDA(text))
296296
except Exception as e:
297-
log.error(e)
297+
log.exception(e)
298298
# Translators: this message directs users to look in the log file
299299
speech.speakMessage(_("Error in navigating math: see NVDA error log for details"))
300300

@@ -315,7 +315,7 @@ def script_navigate(self, gesture: KeyboardInputGesture):
315315
braille.handler.buffer.update()
316316
braille.handler.update()
317317
except Exception as e:
318-
log.error(e)
318+
log.exception(e)
319319
# Translators: this message directs users to look in the log file
320320
speech.speakMessage(_("Error in brailling math: see NVDA error log for details"))
321321

@@ -335,7 +335,7 @@ def script_rawdataToClip(self, gesture: KeyboardInputGesture):
335335
try:
336336
copy_as = libmathcat.GetPreference("CopyAs").lower()
337337
except Exception as e:
338-
log.error(f"Not able to get 'CopyAs' preference: {e}")
338+
log.exception(f"Not able to get 'CopyAs' preference: {e}")
339339
if copy_as == "asciimath" or copy_as == "latex":
340340
# save the old braille code, set the new one, get the braille, then reset the code
341341
saved_braille_code: str = libmathcat.GetPreference("BrailleCode")
@@ -358,7 +358,7 @@ def script_rawdataToClip(self, gesture: KeyboardInputGesture):
358358
# Translators: copy to clipboard
359359
ui.message(_("copy as ") + copy_as)
360360
except Exception as e:
361-
log.error(e)
361+
log.exception(e)
362362
# Translators: this message directs users to look in the log file
363363
speech.speakMessage(_("unable to copy math: see NVDA error log for details"))
364364

@@ -440,7 +440,7 @@ def __init__(self):
440440
libmathcat.SetRulesDir(rules_dir)
441441
libmathcat.SetPreference("TTS", "SSML")
442442
except Exception as e:
443-
log.error(e)
443+
log.exception(e)
444444
# Translators: this message directs users to look in the log file
445445
speech.speakMessage(_("MathCAT initialization failed: see NVDA error log for details"))
446446

@@ -452,8 +452,8 @@ def getSpeechForMathMl(self, mathml: str):
452452
libmathcat.SetPreference("Language", language)
453453
libmathcat.SetMathML(mathml)
454454
except Exception as e:
455-
log.error(e)
456-
log.error(f"MathML is {mathml}")
455+
log.exception(e)
456+
log.exception(f"MathML is {mathml}")
457457
# Translators: this message directs users to look in the log file
458458
speech.speakMessage(_("Illegal MathML found: see NVDA error log for details"))
459459
libmathcat.SetMathML("<math></math>") # set it to something
@@ -483,7 +483,7 @@ def getSpeechForMathMl(self, mathml: str):
483483
return ConvertSSMLTextForNVDA(libmathcat.GetSpokenText())
484484

485485
except Exception as e:
486-
log.error(e)
486+
log.exception(e)
487487
# Translators: this message directs users to look in the log file
488488
speech.speakMessage(_("Error in speaking math: see NVDA error log for details"))
489489
return [""]
@@ -492,23 +492,23 @@ def _add_sounds(self):
492492
try:
493493
return libmathcat.GetPreference("SpeechSound") != "None"
494494
except Exception as e:
495-
log.error(f"MathCAT: An exception occurred in _add_sounds: {e}")
495+
log.exception(f"MathCAT: An exception occurred in _add_sounds: {e}")
496496
return False
497497

498498
def getBrailleForMathMl(self, mathml: str):
499499
# log.info("***MathCAT getBrailleForMathMl")
500500
try:
501501
libmathcat.SetMathML(mathml)
502502
except Exception as e:
503-
log.error(e)
504-
log.error(f"MathML is {mathml}")
503+
log.exception(e)
504+
log.exception(f"MathML is {mathml}")
505505
# Translators: this message directs users to look in the log file
506506
speech.speakMessage(_("Illegal MathML found: see NVDA error log for details"))
507507
libmathcat.SetMathML("<math></math>") # set it to something
508508
try:
509509
return libmathcat.GetBraille("")
510510
except Exception as e:
511-
log.error(e)
511+
log.exception(e)
512512
# Translators: this message directs users to look in the log file
513513
speech.speakMessage(_("Error in brailling math: see NVDA error log for details"))
514514
return ""
@@ -584,7 +584,7 @@ def patched_speak(self, speechSequence: SpeechSequence): # noqa: C901
584584
if item.text:
585585
textList.append(self._processText(item.text))
586586
else:
587-
log.error("Unknown speech: %s" % item)
587+
log.exception("Unknown speech: %s" % item)
588588
# Close any open tags.
589589
if langChanged:
590590
textList.append("</voice>")

addon/globalPlugins/MathCAT/MathCATPreferences.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def getSpeechStyleFromDirectory(dir: str, lang: str) -> list[str]:
391391
this_SpeechStyle if this_SpeechStyle in all_style_files else all_style_files[0]
392392
)
393393
except Exception as e:
394-
log.error(f"MathCAT: An exception occurred in GetSpeechStyles evaluating set SetStringSelection: {e}")
394+
log.exception(f"MathCAT: An exception occurred in GetSpeechStyles evaluating set SetStringSelection: {e}")
395395
# that didn't work, choose the first in the list
396396
self.m_choiceSpeechStyle.SetSelection(0)
397397

@@ -423,15 +423,15 @@ def set_ui_values(self):
423423
break
424424
i += 1
425425
except Exception as e:
426-
log.error(f"MathCAT: An exception occurred in set_ui_values ('{user_preferences['Speech']['Language']}'): {e}")
426+
log.exception(f"MathCAT: An exception occurred in set_ui_values ('{user_preferences['Speech']['Language']}'): {e}")
427427
# the language in the settings file is not in the folder structure, something went wrong,
428428
# set to the first in the list
429429
self.m_choiceLanguage.SetSelection(0)
430430
try:
431431
# now get the available SpeechStyles from the folder structure and set to the preference setting is possible
432432
self.GetSpeechStyles(str(user_preferences["Speech"]["SpeechStyle"]))
433433
except Exception as e:
434-
log.error(f"MathCAT: An exception occurred in set_ui_values (getting SpeechStyle): {e}")
434+
log.exception(f"MathCAT: An exception occurred in set_ui_values (getting SpeechStyle): {e}")
435435
self.m_choiceSpeechStyle.Append(
436436
"Error when setting SpeechStyle for " + self.m_choiceLanguage.GetStringSelection()
437437
)
@@ -483,7 +483,7 @@ def set_ui_values(self):
483483
else:
484484
self.m_choiceBrailleMathCode.SetSelection(0)
485485
except Exception as e:
486-
log.error(f"MathCAT: An exception occurred while trying to set the Braille code: {e}")
486+
log.exception(f"MathCAT: An exception occurred while trying to set the Braille code: {e}")
487487
# the braille code in the settings file is not in the folder structure, something went wrong,
488488
# set to the first in the list
489489
self.m_choiceBrailleMathCode.SetSelection(0)
@@ -576,7 +576,7 @@ def validate(key1: str, key2: str, valid_values: List[Union[str, bool]], default
576576
if user_preferences[key1][key2] in valid_values:
577577
return
578578
except Exception as e:
579-
log.error(f"MathCAT: An exception occurred in validate: {e}")
579+
log.exception(f"MathCAT: An exception occurred in validate: {e}")
580580
# the preferences entry does not exist
581581
if key1 not in user_preferences:
582582
user_preferences[key1] = {key2: default_value}
@@ -591,7 +591,7 @@ def validate_int(key1: str, key2: str, valid_values: List[int], default_value: i
591591
if int(user_preferences[key1][key2]) >= valid_values[0] and int(user_preferences[key1][key2]) <= valid_values[1]:
592592
return
593593
except Exception as e:
594-
log.error(f"MathCAT: An exception occurred in validate_int: {e}")
594+
log.exception(f"MathCAT: An exception occurred in validate_int: {e}")
595595
# the preferences entry does not exist
596596
if key1 not in user_preferences:
597597
user_preferences[key1] = {key2: default_value}
@@ -649,7 +649,7 @@ def write_user_preferences():
649649
try:
650650
libmathcat.SetPreference("Language", user_preferences["Speech"]["Language"])
651651
except Exception as e:
652-
log.error(f'Error in trying to set MathCAT "Language" preference to "{user_preferences["Speech"]["Language"]}": {e}')
652+
log.exception(f'Error in trying to set MathCAT "Language" preference to "{user_preferences["Speech"]["Language"]}": {e}')
653653
if not os.path.exists(UserInterface.path_to_user_preferences_folder()):
654654
# create a folder for the user preferences
655655
os.mkdir(UserInterface.path_to_user_preferences_folder())

0 commit comments

Comments
 (0)