Rename exception variable in makeAlert
This commit is contained in:
@@ -480,7 +480,7 @@ class ProjectBuilder:
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.mainGui.makeAlert(self.tr(
|
self.mainGui.makeAlert(self.tr(
|
||||||
"Failed to create a new example project."
|
"Failed to create a new example project."
|
||||||
), level=nwAlert.ERROR, exception=exc)
|
), level=nwAlert.ERROR, exc=exc)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ class NWProject(QObject):
|
|||||||
if not xmlWriter.write(self._data, content, saveTime, editTime):
|
if not xmlWriter.write(self._data, content, saveTime, editTime):
|
||||||
self.mainGui.makeAlert(self.tr(
|
self.mainGui.makeAlert(self.tr(
|
||||||
"Failed to save project."
|
"Failed to save project."
|
||||||
), level=nwAlert.ERROR, exception=xmlWriter.error)
|
), level=nwAlert.ERROR, exc=xmlWriter.error)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Save other project data
|
# Save other project data
|
||||||
@@ -430,7 +430,7 @@ class NWProject(QObject):
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.mainGui.makeAlert(self.tr(
|
self.mainGui.makeAlert(self.tr(
|
||||||
"Could not create backup folder."
|
"Could not create backup folder."
|
||||||
), level=nwAlert.ERROR, exception=exc)
|
), level=nwAlert.ERROR, exc=exc)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
timeStamp = formatTimeStamp(time(), fileSafe=True)
|
timeStamp = formatTimeStamp(time(), fileSafe=True)
|
||||||
|
|||||||
@@ -752,7 +752,7 @@ class GuiMain(QMainWindow):
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.makeAlert(self.tr(
|
self.makeAlert(self.tr(
|
||||||
"Could not read file. The file must be an existing text file."
|
"Could not read file. The file must be an existing text file."
|
||||||
), level=nwAlert.ERROR, exception=exc)
|
), level=nwAlert.ERROR, exc=exc)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.docEditor.docHandle() is None:
|
if self.docEditor.docHandle() is None:
|
||||||
@@ -1094,21 +1094,19 @@ class GuiMain(QMainWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def makeAlert(self, text: str, info: str = "", details: str = "",
|
def makeAlert(self, text: str, info: str = "", details: str = "",
|
||||||
level: nwAlert = nwAlert.INFO, exception: Exception | None = None) -> None:
|
level: nwAlert = nwAlert.INFO, exc: Exception | None = None) -> None:
|
||||||
"""Alert both the user and the logger at the same time. The
|
"""Alert both the user and the logger at the same time."""
|
||||||
message can be either a string or a list of strings.
|
|
||||||
"""
|
|
||||||
logText = " ".join(filter(None, [text, info, details]))
|
logText = " ".join(filter(None, [text, info, details]))
|
||||||
if level == nwAlert.INFO:
|
if level == nwAlert.INFO:
|
||||||
logger.info(logText, stacklevel=2)
|
logger.info(logText, stacklevel=2)
|
||||||
elif level == nwAlert.WARN:
|
elif level == nwAlert.WARN:
|
||||||
logger.warning(logText, stacklevel=2)
|
logger.warning(logText, stacklevel=2)
|
||||||
elif level == nwAlert.ERROR:
|
elif level == nwAlert.ERROR:
|
||||||
logger.error(logText, stacklevel=2, exc_info=exception)
|
logger.error(logText, stacklevel=2, exc_info=exc)
|
||||||
|
|
||||||
if exception is not None:
|
if exc is not None:
|
||||||
excText = f"{type(exception).__name__}: {str(exception)}"
|
tExc = f"{type(exc).__name__}: {str(exc)}"
|
||||||
info = f"{info}<br>{excText}" if info else excText
|
info = f"{info}<br>{tExc}" if info else tExc
|
||||||
|
|
||||||
msgBox = QMessageBox(self)
|
msgBox = QMessageBox(self)
|
||||||
msgBox.setWindowTitle(trConst(nwLabels.ALERT_NAME[level]))
|
msgBox.setWindowTitle(trConst(nwLabels.ALERT_NAME[level]))
|
||||||
|
|||||||
+1
-1
@@ -51,7 +51,7 @@ class MockGuiMain(QObject):
|
|||||||
def postLaunchTasks(self, cmdOpen):
|
def postLaunchTasks(self, cmdOpen):
|
||||||
return
|
return
|
||||||
|
|
||||||
def makeAlert(self, text, info="", detals="", level=0, exception=None):
|
def makeAlert(self, text, info="", detals="", level=0, exc=None):
|
||||||
assert isinstance(text, str)
|
assert isinstance(text, str)
|
||||||
print("%s: %s" % (str(level), text))
|
print("%s: %s" % (str(level), text))
|
||||||
self.lastAlert = str(text)
|
self.lastAlert = str(text)
|
||||||
|
|||||||
Reference in New Issue
Block a user