mitmproxy/mitmproxy
Nicolas Jeker d72b92bdff
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
2023-11-18 10:03:50 +01:00
..
addons Show exception and stack trace on startup errors (#6491) 2023-11-18 10:03:50 +01:00
contentviews Migrate to ruff (#6433) 2023-10-31 16:03:53 +01:00
contrib [autofix.ci] apply automated fixes 2023-02-27 08:37:11 +01:00
coretypes Migrate to ruff (#6433) 2023-10-31 16:03:53 +01:00
io Migrate to ruff (#6433) 2023-10-31 16:03:53 +01:00
net Migrate to ruff (#6433) 2023-10-31 16:03:53 +01:00
platform [autofix.ci] apply automated fixes 2023-02-27 08:37:11 +01:00
proxy Rename: osproxy -> local redirector (#6453) 2023-11-04 10:52:18 +00:00
script [autofix.ci] apply automated fixes 2022-11-29 13:28:41 +00:00
test [autofix.ci] apply automated fixes 2023-02-27 08:37:11 +01:00
tools Remove stray replay-extra (#6485) 2023-11-14 12:52:16 +00:00
utils Migrate to ruff (#6433) 2023-10-31 16:03:53 +01:00
__init__.py
addonmanager.py Migrate to ruff (#6433) 2023-10-31 16:03:53 +01:00
certs.py Migrate to ruff (#6433) 2023-10-31 16:03:53 +01:00
command.py Command signature inspection fix (#6029) (#6032) 2023-03-29 11:13:54 +00:00
command_lexer.py
connection.py Improve docstring for Server.address (#6352) 2023-09-05 13:40:55 +00:00
ctx.py
dns.py disallow bare except statements (#6017) 2023-03-26 13:57:48 +00:00
eventsequence.py [autofix.ci] apply automated fixes 2023-02-27 08:37:11 +01:00
exceptions.py Fix running hook issue and signal proxyserver updates. (#5512) 2022-08-14 00:11:01 +02:00
flow.py [autofix.ci] apply automated fixes 2023-02-27 08:37:11 +01:00
flowfilter.py [autofix.ci] apply automated fixes 2023-02-27 08:37:11 +01:00
hooks.py cleanups and mypy 1.1.1 fixes (#5977) 2023-03-08 12:14:12 +00:00
http.py Migrate to ruff (#6433) 2023-10-31 16:03:53 +01:00
log.py Declare Support for Python 3.12 (#6434) 2023-10-31 17:57:21 +00:00
master.py Spell "error" properly (#6418) 2023-10-26 16:58:20 +02:00
options.py add option to disable HTTP/3 2023-03-05 19:55:24 +01:00
optmanager.py Migrate to ruff (#6433) 2023-10-31 16:03:53 +01:00
py.typed
tcp.py [autofix.ci] apply automated fixes 2022-11-29 13:28:41 +00:00
tls.py [autofix.ci] apply automated fixes 2023-02-27 08:37:11 +01:00
types.py [autofix.ci] apply automated fixes 2023-02-27 08:37:11 +01:00
udp.py [autofix.ci] apply automated fixes 2022-11-29 13:28:41 +00:00
version.py reopen main for development 2023-11-14 12:54:48 +00:00
websocket.py [autofix.ci] apply automated fixes 2023-02-27 08:37:11 +01:00