Hard exit on script error


#1

Hi there,

What is the recommended way to exit hard from a script in the event of an error? I triggered an error by introducing a nonsense line and can see the printout for it, but the process stays up even after the error:

Script error: Traceback (most recent call last):
  File "/gateway_mitmproxy_script.py", line 93, in tcp_message
    deliberate_syntax_error = foo
NameError: name 'foo' is not defined

The reason that I ask is that I’m running mitmproxy in a docker container that is being watched by another process, and I would like the docker container to exit when there is an error in the script.


#2

This is currently more or less intended behavior as we want you to be able to live-edit a mitmproxy script. We automatically pick up changes to scripts while mitmproxy is running. Temporary syntax errors are a common occurence in that case and shouldn’t exit mitmproxy right away. I’m not sure what happens if the script is invalid right away, but I’d certainly be happy to accept a PR that makes mitmproxy fail right away in that case.


#3

Thank you for clarifying! Sounds like maybe a good PR would be to have a command line option on mitmdump that changes the default failure behavior - I’ll think it over.