From 50f1495f29adee2d3eda011693518ca5ba938037 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 16 Jul 2016 10:56:33 +1200 Subject: [PATCH] Make mitmdump return an error exit status if errors occurred during run --- mitmproxy/dump.py | 3 +++ mitmproxy/main.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py index b95d2627a..18c24d617 100644 --- a/mitmproxy/dump.py +++ b/mitmproxy/dump.py @@ -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, diff --git a/mitmproxy/main.py b/mitmproxy/main.py index 5ced709b9..316db91a8 100644 --- a/mitmproxy/main.py +++ b/mitmproxy/main.py @@ -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