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