Use the logException function in all places where exception messages are written to the error log
This commit is contained in:
+2
-2
@@ -268,9 +268,9 @@ def main(sysArgs=None):
|
||||
bundle = NSBundle.mainBundle()
|
||||
info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
|
||||
info["CFBundleName"] = "novelWriter"
|
||||
except ImportError as e:
|
||||
except ImportError:
|
||||
logger.error("Failed to set application name")
|
||||
logException(e)
|
||||
logException()
|
||||
|
||||
# Import GUI (after dependency checks), and launch
|
||||
from nw.guimain import GuiMain
|
||||
|
||||
+7
-6
@@ -38,6 +38,7 @@ from PyQt5.QtCore import QT_VERSION_STR, QStandardPaths, QSysInfo
|
||||
|
||||
from nw.constants import nwConst, nwFiles, nwUnicode
|
||||
from nw.common import splitVersionNumber, formatTimeStamp
|
||||
from nw.error import logException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -293,7 +294,7 @@ class Config:
|
||||
os.mkdir(self.confPath)
|
||||
except Exception as e:
|
||||
logger.error("Could not create folder: %s" % self.confPath)
|
||||
logger.error(str(e))
|
||||
logException()
|
||||
self.hasError = True
|
||||
self.errData.append("Could not create folder: %s" % self.confPath)
|
||||
self.errData.append(str(e))
|
||||
@@ -316,7 +317,7 @@ class Config:
|
||||
os.mkdir(self.dataPath)
|
||||
except Exception as e:
|
||||
logger.error("Could not create folder: %s" % self.dataPath)
|
||||
logger.error(str(e))
|
||||
logException()
|
||||
self.hasError = True
|
||||
self.errData.append("Could not create folder: %s" % self.dataPath)
|
||||
self.errData.append(str(e))
|
||||
@@ -361,7 +362,7 @@ class Config:
|
||||
cnfParse.read_file(inFile)
|
||||
except Exception as e:
|
||||
logger.error("Could not load config file")
|
||||
logger.error(str(e))
|
||||
logException()
|
||||
self.hasError = True
|
||||
self.errData.append("Could not load config file")
|
||||
self.errData.append(str(e))
|
||||
@@ -702,7 +703,7 @@ class Config:
|
||||
self.confChanged = False
|
||||
except Exception as e:
|
||||
logger.error("Could not save config file")
|
||||
logger.error(str(e))
|
||||
logException()
|
||||
self.hasError = True
|
||||
self.errData.append("Could not save config file")
|
||||
self.errData.append(str(e))
|
||||
@@ -978,9 +979,9 @@ class Config:
|
||||
return self._unpackList(
|
||||
cnfParse.get(cnfSec, cnfName), cnfDefault, self.CNF_S_LST
|
||||
)
|
||||
except ValueError as e:
|
||||
except ValueError:
|
||||
logger.error("Failed to load value from config file.")
|
||||
logger.error(str(e))
|
||||
logException()
|
||||
return cnfDefault
|
||||
|
||||
return cnfDefault
|
||||
|
||||
+6
-6
@@ -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
@@ -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
@@ -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
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ logger = logging.getLogger(__name__)
|
||||
# Utility Functions
|
||||
# =============================================================================================== #
|
||||
|
||||
def logException(exObj):
|
||||
def logException():
|
||||
"""Log the content of an exception message.
|
||||
"""
|
||||
exType, exValue, _ = sys.exc_info()
|
||||
|
||||
+6
-6
@@ -671,9 +671,9 @@ class GuiBuildNovel(QDialog):
|
||||
bldObj.doConvert()
|
||||
bldObj.doPostProcessing()
|
||||
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.error("Failed to generate html of document '%s'" % tItem.itemHandle)
|
||||
logger.error(str(e))
|
||||
nw.logException()
|
||||
if isPreview:
|
||||
self.docView.setText((
|
||||
"Failed to generate preview. "
|
||||
@@ -997,9 +997,9 @@ class GuiBuildNovel(QDialog):
|
||||
with open(buildCache, mode="r", encoding="utf8") as inFile:
|
||||
theJson = inFile.read()
|
||||
theData = json.loads(theJson)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.error("Failed to load build cache")
|
||||
logger.error(str(e))
|
||||
nw.logException()
|
||||
return False
|
||||
|
||||
if "htmlText" in theData.keys():
|
||||
@@ -1026,9 +1026,9 @@ class GuiBuildNovel(QDialog):
|
||||
"htmlStyle" : self.htmlStyle,
|
||||
"buildTime" : self.buildTime,
|
||||
}, indent=2))
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.error("Failed to save build cache")
|
||||
logger.error(str(e))
|
||||
nw.logException()
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
+2
-2
@@ -180,9 +180,9 @@ class GuiDocViewer(QTextBrowser):
|
||||
aDoc.tokenizeText()
|
||||
aDoc.doConvert()
|
||||
aDoc.doPostProcessing()
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.error("Failed to generate preview for document with handle '%s'" % tHandle)
|
||||
logger.error(str(e))
|
||||
nw.logException()
|
||||
self.setText("An error occurred while generating the preview.")
|
||||
return False
|
||||
|
||||
|
||||
+8
-8
@@ -265,9 +265,9 @@ class GuiTheme:
|
||||
if os.path.isfile(self.cssFile):
|
||||
with open(self.cssFile, mode="r", encoding="utf8") as inFile:
|
||||
cssData = inFile.read()
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.error("Could not load theme css file")
|
||||
logger.error(str(e))
|
||||
nw.logException()
|
||||
return False
|
||||
|
||||
# Config File
|
||||
@@ -275,9 +275,9 @@ class GuiTheme:
|
||||
try:
|
||||
with open(self.confFile, mode="r", encoding="utf8") as inFile:
|
||||
confParser.read_file(inFile)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.error("Could not load theme settings from: %s" % self.confFile)
|
||||
logger.error(str(e))
|
||||
nw.logException()
|
||||
return False
|
||||
|
||||
## Main
|
||||
@@ -333,9 +333,9 @@ class GuiTheme:
|
||||
try:
|
||||
with open(self.syntaxFile, mode="r", encoding="utf8") as inFile:
|
||||
confParser.read_file(inFile)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.error("Could not load syntax colours from: %s" % self.syntaxFile)
|
||||
logger.error(str(e))
|
||||
nw.logException()
|
||||
return False
|
||||
|
||||
## Main
|
||||
@@ -637,9 +637,9 @@ class GuiIcons:
|
||||
try:
|
||||
with open(self.confFile, mode="r", encoding="utf8") as inFile:
|
||||
confParser.read_file(inFile)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.error("Could not load icon theme settings from: %s" % self.confFile)
|
||||
logger.error(str(e))
|
||||
nw.logException()
|
||||
return False
|
||||
|
||||
## Main
|
||||
|
||||
Reference in New Issue
Block a user