qt console: fix tracebacks in windows binaries
fixes https://github.com/spesmilo/electrum/issues/3315 The cause was that tracebacks look different whether stack items have source text available. When using the pyinstaller windows binary, there is no source text available. Example when running from source: ``` >>> a Traceback (most recent call last): File "...\electrum\gui\qt\console.py", line 256, in exec_command result = eval(command, self.namespace, self.namespace) File "<string>", line 1, in <module> NameError: name 'a' is not defined ``` Example for pyinstaller windows binary: ``` >>> a Traceback (most recent call last): File "electrum\gui\qt\console.py", line 256, in exec_command File "<string>", line 1, in <module> NameError: name 'a' is not defined ```
This commit is contained in:
@@ -264,12 +264,18 @@ class Console(QtWidgets.QPlainTextEdit):
|
||||
exec(command, self.namespace, self.namespace)
|
||||
except SystemExit:
|
||||
self.close()
|
||||
except BaseException:
|
||||
traceback_lines = traceback.format_exc().split('\n')
|
||||
# Remove traceback mentioning this file, and a linebreak
|
||||
for i in (3,2,1,-1):
|
||||
traceback_lines.pop(i)
|
||||
self.appendPlainText('\n'.join(traceback_lines))
|
||||
except BaseException as e:
|
||||
te = traceback.TracebackException.from_exception(e)
|
||||
# rm part of traceback mentioning this file.
|
||||
# (note: we rm stack items before converting to str, instead of removing lines from the str,
|
||||
# as this is more reliable. The latter would differ whether the traceback has source text lines,
|
||||
# which is not always the case.)
|
||||
te.stack = traceback.StackSummary.from_list(te.stack[1:])
|
||||
tb_str = "".join(te.format())
|
||||
# rm last linebreak:
|
||||
if tb_str.endswith("\n"):
|
||||
tb_str = tb_str[:-1]
|
||||
self.appendPlainText(tb_str)
|
||||
sys.stdout = tmp_stdout
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
|
||||
Reference in New Issue
Block a user