Make mitmdump return an error exit status if errors occurred during run

This commit is contained in:
Aldo Cortesi 2016-07-16 10:56:33 +12:00
parent 33d03d916a
commit 50f1495f29
2 changed files with 6 additions and 0 deletions

View File

@ -45,6 +45,7 @@ class DumpMaster(flow.FlowMaster):
def __init__(self, server, options):
flow.FlowMaster.__init__(self, options, server, flow.State())
self.has_errored = False
self.addons.add(*builtins.default_addons())
# This line is just for type hinting
self.options = self.options # type: Options
@ -115,6 +116,8 @@ class DumpMaster(flow.FlowMaster):
raise DumpError(str(e))
def add_log(self, e, level="info"):
if level == "error":
self.has_errored = True
if self.options.verbosity >= utils.log_tier(level):
self.echo(
e,

View File

@ -118,6 +118,9 @@ def mitmdump(args=None): # pragma: no cover
sys.exit(1)
except (KeyboardInterrupt, _thread.error):
pass
if master.has_errored:
print("mitmdump: errors occurred during run", file=sys.stderr)
sys.exit(1)
def mitmweb(args=None): # pragma: no cover