mirror of
https://github.com/vee1e/mitmproxy.git
synced 2026-09-01 18:27:18 +00:00
Show exception and stack trace on startup errors (#6491)
#### Description
It's hard to debug errors raised in addon scripts during startup as only
a generic message is output on the console. Using logger.format() to
format errors that occurred during startup instead of only displaying
the LogRecord.msg improves the output if an exception is present by
showing the stack trace. An additional newline was added for better
readability.
Comparison with the load_error.py test script, before:
$ mitmproxy -s test/mitmproxy/data/addonscripts/load_error.py
Error logged during startup: Addon error:
After:
$ mitmproxy -s test/mitmproxy/data/addonscripts/load_error.py
Error logged during startup:
Addon error:
Traceback (most recent call last):
File "test/mitmproxy/data/addonscripts/load_error.py", line 2, in load
raise ValueError()
ValueError
Relates to issue #5935 and PR #6020
#### Checklist
- [ ] I have updated tests where applicable.
- I think the value of extending `test_errorcheck.py` for this behavior
is low and tightly couples the test to `logger.format()`
- [ ] I have added an entry to the CHANGELOG.
- #6020 didn't introduce a changelog entry, so I figured this won't need
one either
This commit is contained in:
parent
504d6bd2c5
commit
d72b92bdff
1 changed files with 2 additions and 2 deletions
|
|
@ -29,8 +29,8 @@ class ErrorCheck:
|
|||
if self.logger.has_errored:
|
||||
plural = "s" if len(self.logger.has_errored) > 1 else ""
|
||||
if self.repeat_errors_on_stderr:
|
||||
msg = "\n".join(r.msg for r in self.logger.has_errored)
|
||||
print(f"Error{plural} logged during startup: {msg}", file=sys.stderr)
|
||||
msg = "\n".join(self.logger.format(r) for r in self.logger.has_errored)
|
||||
print(f"Error{plural} logged during startup:\n{msg}", file=sys.stderr)
|
||||
else:
|
||||
print(
|
||||
f"Error{plural} logged during startup, exiting...", file=sys.stderr
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue