Use the logException function in all places where exception messages are written to the error log

This commit is contained in:
Veronica K. B. Olsen
2021-01-29 18:29:50 +01:00
parent a2f223a992
commit 89ba4aeeaf
11 changed files with 72 additions and 63 deletions
+6 -6
View File
@@ -154,9 +154,9 @@ class NWIndex():
try:
with open(indexFile, mode="r", encoding="utf8") as inFile:
theData = json.load(inFile)
except Exception as e:
except Exception:
logger.error("Failed to load index file")
logger.error(str(e))
nw.logException()
self.indexBroken = True
self.theParent.makeAlert(
"Could not load cached index file. Rebuilding index.",
@@ -195,9 +195,9 @@ class NWIndex():
"noteIndex" : self._noteIndex,
"textCounts" : self._textCounts,
}, outFile, indent=2)
except Exception as e:
except Exception:
logger.error("Failed to save index file")
logger.error(str(e))
nw.logException()
return False
return True
@@ -217,9 +217,9 @@ class NWIndex():
self._checkTextCounts()
self.indexBroken = False
except Exception as e:
except Exception:
logger.error("Error while checking index")
nw.logException(e)
nw.logException()
self.indexBroken = True
tEnd = time()
+5 -4
View File
@@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import nw
import logging
import json
import os
@@ -121,9 +122,9 @@ class OptionState():
try:
with open(stateFile, mode="r", encoding="utf8") as inFile:
theState = json.load(inFile)
except Exception as e:
except Exception:
logger.error("Failed to load GUI options file")
logger.error(str(e))
nw.logException()
return False
# Filter out unused variables
@@ -148,9 +149,9 @@ class OptionState():
try:
with open(stateFile, mode="w+", encoding="utf8") as outFile:
json.dump(self.theState, outFile, indent=2)
except Exception as e:
except Exception:
logger.error("Failed to save GUI options file")
logger.error(str(e))
nw.logException()
return False
return True
+23 -18
View File
@@ -1219,9 +1219,9 @@ class NWProject():
if len(theLines) != 4:
return ["ERROR"]
except Exception as e:
except Exception:
logger.error("Failed to read project lockfile")
logger.error(str(e))
nw.logException()
return ["ERROR"]
return theLines
@@ -1240,9 +1240,9 @@ class NWProject():
outFile.write("%s\n" % self.mainConf.kernelVer)
outFile.write("%d\n" % time())
except Exception as e:
except Exception:
logger.error("Failed to write project lockfile")
logger.error(str(e))
nw.logException()
return False
return True
@@ -1257,9 +1257,9 @@ class NWProject():
if os.path.isfile(lockFile):
try:
os.unlink(lockFile)
except Exception as e:
except Exception:
logger.error("Failed to remove project lockfile")
logger.error(str(e))
nw.logException()
return False
return True
@@ -1415,9 +1415,9 @@ class NWProject():
self.notesWCount,
))
except Exception as e:
except Exception:
logger.error("Failed to write session stats file")
logger.error(str(e))
nw.logException()
return False
return True
@@ -1453,17 +1453,19 @@ class NWProject():
os.rename(theFile, newPath)
logger.info("Moved file: %s" % theFile)
logger.info("New location: %s" % newPath)
except Exception as e:
logger.error(str(e))
except Exception:
errList.append("Could not move: %s" % theFile)
logger.error("Could not move: %s" % theFile)
nw.logException()
elif len(dataItem) == 21 and dataItem.endswith("_main.bak"):
try:
os.unlink(theFile)
logger.info("Deleted file: %s" % theFile)
except Exception as e:
logger.error(str(e))
except Exception:
errList.append("Could not delete: %s" % theFile)
logger.error("Could not delete: %s" % theFile)
nw.logException()
else:
theErr = self._moveUnknownItem(theData, dataItem)
@@ -1475,9 +1477,10 @@ class NWProject():
try:
os.rmdir(theData)
logger.info("Removed folder: %s" % theFolder)
except Exception as e:
logger.error(str(e))
except Exception:
errList.append("Failed to remove: %s" % theFolder)
logger.error("Failed to remove: %s" % theFolder)
nw.logException()
return errList
@@ -1495,8 +1498,9 @@ class NWProject():
try:
os.rename(theSrc, theDst)
logger.info("Moved to junk: %s" % theSrc)
except Exception as e:
logger.error(str(e))
except Exception:
logger.error("Could not move item %s to junk." % theSrc)
nw.logException()
return "Could not move item %s to junk." % theSrc
return ""
@@ -1529,8 +1533,9 @@ class NWProject():
logger.info("Deleting: %s" % rmFile)
try:
os.unlink(rmFile)
except Exception as e:
logger.error(str(e))
except Exception:
logger.error("Could not delete: %s" % rmFile)
nw.logException()
return False
return True
+8 -8
View File
@@ -72,9 +72,9 @@ class NWSpellCheck():
with open(self.projectDict, mode="a+", encoding="utf-8") as outFile:
outFile.write("%s\n" % newWord)
self.projDict.append(newWord)
except Exception as e:
except Exception:
logger.error("Failed to add word to project word list %s" % str(self.projectDict))
logger.error(str(e))
nw.logException()
return False
return True
return False
@@ -123,9 +123,9 @@ class NWSpellCheck():
if len(theLine) > 0 and theLine not in self.projDict:
self.projDict.append(theLine)
logger.debug("Project word list contains %d words" % len(self.projDict))
except Exception as e:
except Exception:
logger.error("Failed to load project word list")
logger.error(str(e))
nw.logException()
return False
return True
@@ -201,9 +201,9 @@ class NWSpellEnchant(NWSpellCheck):
try:
spTag = self.theDict.tag
spName = self.theDict.provider.name
except Exception as e:
except Exception:
logger.error("Failed to extract information about the dictionary")
logger.error(str(e))
nw.logException()
spTag = ""
spName = ""
@@ -261,9 +261,9 @@ class NWSpellSimple(NWSpellCheck):
logger.debug("Spell check word list for language %s loaded" % theLang)
logger.debug("Word list contains %d words" % len(self.WORDS))
self.spellLanguage = theLang
except Exception as e:
except Exception:
logger.error("Failed to load spell check word list for language %s" % theLang)
logger.error(str(e))
nw.logException()
self.spellLanguage = None
self._readProjectDictionary(projectDict)
+4 -2
View File
@@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import nw
import logging
import os
@@ -179,8 +180,9 @@ class NWTree():
outFile.write("\n".join(tocList))
outFile.write("\n")
except Exception as e:
logger.error(str(e))
except Exception:
logger.error("Could not write ToC file")
nw.logException()
return False
return True