From 6d67286bd1e68b12fb1151cc6790e3a4bdadbe57 Mon Sep 17 00:00:00 2001 From: Henrique Date: Sat, 23 Nov 2019 16:31:21 -0500 Subject: Fix to check if command_history file exists prior to trying to read it --- mitmproxy/addons/command_history.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mitmproxy/addons/command_history.py b/mitmproxy/addons/command_history.py index 2c348d1e..113af213 100644 --- a/mitmproxy/addons/command_history.py +++ b/mitmproxy/addons/command_history.py @@ -7,6 +7,7 @@ import mitmproxy.options import mitmproxy.types from mitmproxy import command +from mitmproxy import ctx from mitmproxy.tools.console.commander.commander import CommandBuffer @@ -22,8 +23,10 @@ class CommandHistory: self.filtered_commands: typing.Deque[str] = collections.deque() self.filter_active: bool = True - _command_history_path = os.path.join(os.path.expanduser(mitmproxy.options.CONF_DIR), 'command_history') - _history_lines = open(_command_history_path, 'r').readlines() + _command_history_path = os.path.join(os.path.expanduser(ctx.options.confdir), 'command_history') + _history_lines = [] + if os.path.exists(_command_history_path): + _history_lines = open(_command_history_path, 'r').readlines() self.command_history_file = open(_command_history_path, 'w') -- cgit v1.2.3