gurudesh/pytracebugs huggingface dataset:
# Buggy code
def shutdown(self):
    if not self.should_exit.is_set():
        self.should_exit.set()
        if self.server:
            self.server.shutdown()


# Traceback (AttributeError)
./mitmdump.run.sh: line 2: 14504 Segmentation fault      mitmdump -p 59873 > network
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/server.py", line 120, in handle
root_layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/modes/http_proxy.py", line 10, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 323, in __call__
self.handle_regular_mode_connect(request)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 409, in handle_regular_mode_connect
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 340, in __call__
self.get_response_from_server(flow)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 471, in get_response_from_server
if flow.response.stream:
AttributeError: 'NoneType' object has no attribute 'response'

# Fixed code
def shutdown(self):
    self.should_exit.set()
# Buggy code
def ask(self, mtype, m):
    """
    Decorate a message with a reply attribute, and send it to the
    master.  then wait for a response.
    """
    m.reply = Reply(m)
    self.q.put((mtype, m))
    while not self.should_exit.is_set():
        try:
            # The timeout is here so we can handle a should_exit event.
            g = m.reply.q.get(timeout=0.5)
        except queue.Empty:  # pragma: no cover
            continue
        return g


# Traceback (AttributeError)
./mitmdump.run.sh: line 2: 14504 Segmentation fault      mitmdump -p 59873 > network
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/server.py", line 120, in handle
root_layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/modes/http_proxy.py", line 10, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 323, in __call__
self.handle_regular_mode_connect(request)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 409, in handle_regular_mode_connect
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 340, in __call__
self.get_response_from_server(flow)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 471, in get_response_from_server
if flow.response.stream:
AttributeError: 'NoneType' object has no attribute 'response'

# Fixed code
def ask(self, mtype, m):
    """
    Decorate a message with a reply attribute, and send it to the
    master. Then wait for a response.

    Raises:
        Kill: All connections should be closed immediately.
    """
    m.reply = Reply(m)
    self.q.put((mtype, m))
    while not self.should_exit.is_set():
        try:
            # The timeout is here so we can handle a should_exit event.
            g = m.reply.q.get(timeout=0.5)
        except queue.Empty:  # pragma: no cover
            continue
        if g == Kill:
            raise Kill()
        return g

    raise Kill()
# Buggy code
def __call__(self, msg=None):
    if not self.acked:
        self.acked = True
        if msg is None:
            self.q.put(self.obj)
        else:
            self.q.put(msg)


# Traceback (AttributeError)
./mitmdump.run.sh: line 2: 14504 Segmentation fault      mitmdump -p 59873 > network
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/server.py", line 120, in handle
root_layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/modes/http_proxy.py", line 10, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 323, in __call__
self.handle_regular_mode_connect(request)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 409, in handle_regular_mode_connect
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 340, in __call__
self.get_response_from_server(flow)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 471, in get_response_from_server
if flow.response.stream:
AttributeError: 'NoneType' object has no attribute 'response'

# Fixed code
def __call__(self, msg=NO_REPLY):
    if not self.acked:
        self.acked = True
        if msg is NO_REPLY:
            self.q.put(self.obj)
        else:
            self.q.put(msg)
# Buggy code
def run(self):  # pragma: no cover
    if self.o.rfile and not self.o.keepserving:
        self.shutdown()
        return
    try:
        return super(DumpMaster, self).run()
    except BaseException:
        self.shutdown()
        raise


# Traceback (AttributeError)
./mitmdump.run.sh: line 2: 14504 Segmentation fault      mitmdump -p 59873 > network
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/server.py", line 120, in handle
root_layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/modes/http_proxy.py", line 10, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 323, in __call__
self.handle_regular_mode_connect(request)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 409, in handle_regular_mode_connect
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 340, in __call__
self.get_response_from_server(flow)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 471, in get_response_from_server
if flow.response.stream:
AttributeError: 'NoneType' object has no attribute 'response'

# Fixed code
def run(self):  # pragma: no cover
    if self.o.rfile and not self.o.keepserving:
        self.shutdown()
        return
    super(DumpMaster, self).run()
# Buggy code
def __init__(self, server, state):
    controller.Master.__init__(self, server)
    self.state = state
    self.server_playback = None
    self.client_playback = None
    self.kill_nonreplay = False
    self.scripts = []
    self.pause_scripts = False

    self.stickycookie_state = False
    self.stickycookie_txt = None

    self.stickyauth_state = False
    self.stickyauth_txt = None

    self.anticache = False
    self.anticomp = False
    self.stream_large_bodies = False
    self.refresh_server_playback = False
    self.replacehooks = ReplaceHooks()
    self.setheaders = SetHeaders()
    self.replay_ignore_params = False
    self.replay_ignore_content = None
    self.replay_ignore_host = False

    self.stream = None
    self.apps = AppRegistry()


# Traceback (AttributeError)
./mitmdump.run.sh: line 2: 14504 Segmentation fault      mitmdump -p 59873 > network
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/server.py", line 120, in handle
root_layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/modes/http_proxy.py", line 10, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 323, in __call__
self.handle_regular_mode_connect(request)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 409, in handle_regular_mode_connect
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 340, in __call__
self.get_response_from_server(flow)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 471, in get_response_from_server
if flow.response.stream:
AttributeError: 'NoneType' object has no attribute 'response'

# Fixed code
def __init__(self, server, state):
    super(FlowMaster, self).__init__()
    if server:
        self.add_server(server)
    self.state = state
    self.server_playback = None
    self.client_playback = None
    self.kill_nonreplay = False
    self.scripts = []
    self.pause_scripts = False

    self.stickycookie_state = False
    self.stickycookie_txt = None

    self.stickyauth_state = False
    self.stickyauth_txt = None

    self.anticache = False
    self.anticomp = False
    self.stream_large_bodies = False
    self.refresh_server_playback = False
    self.replacehooks = ReplaceHooks()
    self.setheaders = SetHeaders()
    self.replay_ignore_params = False
    self.replay_ignore_content = None
    self.replay_ignore_host = False

    self.stream = None
    self.apps = AppRegistry()
# Buggy code
def load_script(self, command, use_reloader=False):
    """
    Loads a script. Returns an error description if something went
    wrong.
    """
    try:
        s = script.Script(command, script.ScriptContext(self))
        s.load()
    except script.ScriptException as e:
        return traceback.format_exc(e)
    if use_reloader:
        script.reloader.watch(s, lambda: self.masterq.put(("script_change", s)))
    self.scripts.append(s)


# Traceback (AttributeError)
./mitmdump.run.sh: line 2: 14504 Segmentation fault      mitmdump -p 59873 > network
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/server.py", line 120, in handle
root_layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/modes/http_proxy.py", line 10, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 323, in __call__
self.handle_regular_mode_connect(request)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 409, in handle_regular_mode_connect
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 340, in __call__
self.get_response_from_server(flow)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 471, in get_response_from_server
if flow.response.stream:
AttributeError: 'NoneType' object has no attribute 'response'

# Fixed code
def load_script(self, command, use_reloader=False):
    """
    Loads a script. Returns an error description if something went
    wrong.
    """
    try:
        s = script.Script(command, script.ScriptContext(self))
        s.load()
    except script.ScriptException as e:
        return traceback.format_exc(e)
    if use_reloader:
        script.reloader.watch(s, lambda: self.event_queue.put(("script_change", s)))
    self.scripts.append(s)
# Buggy code
def tick(self, q, timeout):
    if self.client_playback:
        stop = self.client_playback.done() and self.state.active_flow_count() == 0
        exit = self.client_playback.exit
        if stop:
            self.stop_client_playback()
            if exit:
                self.shutdown()
        else:
            self.client_playback.tick(self)

    if self.server_playback:
        stop = (
            self.server_playback.count() == 0
            and self.state.active_flow_count() == 0
            and not self.kill_nonreplay
        )
        exit = self.server_playback.exit
        if stop:
            self.stop_server_playback()
            if exit:
                self.shutdown()
    return super(FlowMaster, self).tick(q, timeout)


# Traceback (AttributeError)
./mitmdump.run.sh: line 2: 14504 Segmentation fault      mitmdump -p 59873 > network
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/server.py", line 120, in handle
root_layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/modes/http_proxy.py", line 10, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 323, in __call__
self.handle_regular_mode_connect(request)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 409, in handle_regular_mode_connect
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 340, in __call__
self.get_response_from_server(flow)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 471, in get_response_from_server
if flow.response.stream:
AttributeError: 'NoneType' object has no attribute 'response'

# Fixed code
def tick(self, timeout):
    if self.client_playback:
        stop = self.client_playback.done() and self.state.active_flow_count() == 0
        exit = self.client_playback.exit
        if stop:
            self.stop_client_playback()
            if exit:
                self.shutdown()
        else:
            self.client_playback.tick(self)

    if self.server_playback:
        stop = (
            self.server_playback.count() == 0
            and self.state.active_flow_count() == 0
            and not self.kill_nonreplay
        )
        exit = self.server_playback.exit
        if stop:
            self.stop_server_playback()
            if exit:
                self.shutdown()
    return super(FlowMaster, self).tick(timeout)
# Buggy code
def shutdown(self):
    self.unload_scripts()
    super(FlowMaster, self).shutdown()

    # Add all flows that are still active
    if self.stream:
        for i in self.state.flows:
            if not i.response:
                self.stream.add(i)
        self.stop_stream()


# Traceback (AttributeError)
./mitmdump.run.sh: line 2: 14504 Segmentation fault      mitmdump -p 59873 > network
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/server.py", line 120, in handle
root_layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/modes/http_proxy.py", line 10, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 323, in __call__
self.handle_regular_mode_connect(request)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 409, in handle_regular_mode_connect
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 340, in __call__
self.get_response_from_server(flow)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 471, in get_response_from_server
if flow.response.stream:
AttributeError: 'NoneType' object has no attribute 'response'

# Fixed code
def shutdown(self):
    super(FlowMaster, self).shutdown()

    # Add all flows that are still active
    if self.stream:
        for i in self.state.flows:
            if not i.response:
                self.stream.add(i)
        self.stop_stream()

    self.unload_scripts()
# Buggy code
def kill(self, master):
    """
    Kill this request.
    """
    from ..protocol import Kill

    self.error = Error("Connection killed")
    self.intercepted = False
    self.reply(Kill)
    master.handle_error(self)


# Traceback (AttributeError)
./mitmdump.run.sh: line 2: 14504 Segmentation fault      mitmdump -p 59873 > network
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/server.py", line 120, in handle
root_layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/modes/http_proxy.py", line 10, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 323, in __call__
self.handle_regular_mode_connect(request)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 409, in handle_regular_mode_connect
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 340, in __call__
self.get_response_from_server(flow)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 471, in get_response_from_server
if flow.response.stream:
AttributeError: 'NoneType' object has no attribute 'response'

# Fixed code
def kill(self, master):
    """
    Kill this request.
    """
    self.error = Error("Connection killed")
    self.intercepted = False
    self.reply(Kill)
    master.handle_error(self)
# Buggy code
def __init__(self, config, flow, masterq, should_exit):
    """
    masterqueue can be a queue or None, if no scripthooks should be
    processed.
    """
    self.config, self.flow = config, flow
    if masterq:
        self.channel = Channel(masterq, should_exit)
    else:
        self.channel = None
    super(RequestReplayThread, self).__init__()


# Traceback (AttributeError)
./mitmdump.run.sh: line 2: 14504 Segmentation fault      mitmdump -p 59873 > network
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/server.py", line 120, in handle
root_layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/modes/http_proxy.py", line 10, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 323, in __call__
self.handle_regular_mode_connect(request)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 409, in handle_regular_mode_connect
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 340, in __call__
self.get_response_from_server(flow)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 471, in get_response_from_server
if flow.response.stream:
AttributeError: 'NoneType' object has no attribute 'response'

# Fixed code
def __init__(self, config, flow, event_queue, should_exit):
    """
    event_queue can be a queue or None, if no scripthooks should be
    processed.
    """
    self.config, self.flow = config, flow
    if event_queue:
        self.channel = Channel(event_queue, should_exit)
    else:
        self.channel = None
    super(RequestReplayThread, self).__init__()
# Buggy code
def run(self):  # pragma: no cover
    self.server.start_slave(
        controller.Slave, controller.Channel(self.masterq, self.should_exit)
    )
    iol = tornado.ioloop.IOLoop.instance()

    http_server = tornado.httpserver.HTTPServer(self.app)
    http_server.listen(self.options.wport)

    tornado.ioloop.PeriodicCallback(self.tick, 5).start()
    try:
        iol.start()
    except (Stop, KeyboardInterrupt):
        self.shutdown()


# Traceback (AttributeError)
./mitmdump.run.sh: line 2: 14504 Segmentation fault      mitmdump -p 59873 > network
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/server.py", line 120, in handle
root_layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/proxy/modes/http_proxy.py", line 10, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 323, in __call__
self.handle_regular_mode_connect(request)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 409, in handle_regular_mode_connect
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/tls.py", line 272, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 130, in __call__
layer()
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 340, in __call__
self.get_response_from_server(flow)
File "/usr/local/lib/python2.7/site-packages/libmproxy/protocol/http.py", line 471, in get_response_from_server
if flow.response.stream:
AttributeError: 'NoneType' object has no attribute 'response'

# Fixed code
def run(self):  # pragma: no cover
    iol = tornado.ioloop.IOLoop.instance()

    http_server = tornado.httpserver.HTTPServer(self.app)
    http_server.listen(self.options.wport)

    iol.add_callback(self.start)
    tornado.ioloop.PeriodicCallback(lambda: self.tick(timeout=0), 5).start()
    try:
        iol.start()
    except (Stop, KeyboardInterrupt):
        self.shutdown()
# Buggy code
def load_flows_file(self, path):
    path = os.path.expanduser(path)
    try:
        f = file(path, "rb")
        freader = FlowReader(f)
    except IOError as v:
        raise FlowReadError(v.strerror)
    return self.load_flows(freader)


# Traceback (ValueError)
Error: Connection killed
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/venv/bin/mitmdump", line 9, in <module>
load_entry_point('mitmproxy', 'console_scripts', 'mitmdump')()
File "/home/christofferqa/mitmproxy/mitmproxy/main.py", line 102, in mitmdump
master.run()
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 354, in run
return flow.FlowMaster.run(self)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 128, in run
self.tick(self.masterq, 0.1)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 828, in tick
return super(FlowMaster, self).tick(q, timeout)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 113, in tick
self.handle(*msg)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 135, in handle
m(obj)
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 337, in handle_response
self._process_flow(f)
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 321, in _process_flow
self.state.delete_flow(f)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 584, in delete_flow
self.flows._remove(f)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 496, in _remove
self._list.remove(f)
ValueError: list.remove(x): x not in list
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 121, in handle
root_layer()
TypeError: 'NoneType' object is not callable

mitmproxy has crashed!
Please lodge a bug report at: https://github.com/mitmproxy/mitmproxy
----------------------------------------
Error in processing of request from 127.0.0.1:41084
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/netlib/tcp.py", line 854, in connection_thread
self.handle_client_connection(connection, client_address)
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 64, in handle_client_connection
h.handle()
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 152, in handle
self.channel.tell("clientdisconnect", root_layer)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 68, in tell
m.reply = DummyReply()
AttributeError: 'NoneType' object has no attribute 'reply'

# Fixed code
def load_flows_file(self, path):
    path = os.path.expanduser(path)
    try:
        with open(path, "rb") as f:
            freader = FlowReader(f)
            return self.load_flows(freader)
    except IOError as v:
        raise FlowReadError(v.strerror)
# Buggy code
def __init__(self, original_reply, script_thread):
    self.original_reply = original_reply
    self.script_thread = script_thread
    self._ignore_call = True
    self.lock = threading.Lock()


# Traceback (ValueError)
Error: Connection killed
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/venv/bin/mitmdump", line 9, in <module>
load_entry_point('mitmproxy', 'console_scripts', 'mitmdump')()
File "/home/christofferqa/mitmproxy/mitmproxy/main.py", line 102, in mitmdump
master.run()
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 354, in run
return flow.FlowMaster.run(self)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 128, in run
self.tick(self.masterq, 0.1)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 828, in tick
return super(FlowMaster, self).tick(q, timeout)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 113, in tick
self.handle(*msg)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 135, in handle
m(obj)
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 337, in handle_response
self._process_flow(f)
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 321, in _process_flow
self.state.delete_flow(f)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 584, in delete_flow
self.flows._remove(f)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 496, in _remove
self._list.remove(f)
ValueError: list.remove(x): x not in list
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 121, in handle
root_layer()
TypeError: 'NoneType' object is not callable

mitmproxy has crashed!
Please lodge a bug report at: https://github.com/mitmproxy/mitmproxy
----------------------------------------
Error in processing of request from 127.0.0.1:41084
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/netlib/tcp.py", line 854, in connection_thread
self.handle_client_connection(connection, client_address)
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 64, in handle_client_connection
h.handle()
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 152, in handle
self.channel.tell("clientdisconnect", root_layer)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 68, in tell
m.reply = DummyReply()
AttributeError: 'NoneType' object has no attribute 'reply'

# Fixed code
def __init__(self, reply_func, script_thread):
    self.reply_func = reply_func
    self.script_thread = script_thread
    self.master_reply = None
# Buggy code
def __call__(self, *args, **kwargs):
    with self.lock:
        if self._ignore_call:
            self.script_thread.start()
            self._ignore_call = False
            return
    self.original_reply(*args, **kwargs)


# Traceback (ValueError)
Error: Connection killed
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/venv/bin/mitmdump", line 9, in <module>
load_entry_point('mitmproxy', 'console_scripts', 'mitmdump')()
File "/home/christofferqa/mitmproxy/mitmproxy/main.py", line 102, in mitmdump
master.run()
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 354, in run
return flow.FlowMaster.run(self)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 128, in run
self.tick(self.masterq, 0.1)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 828, in tick
return super(FlowMaster, self).tick(q, timeout)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 113, in tick
self.handle(*msg)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 135, in handle
m(obj)
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 337, in handle_response
self._process_flow(f)
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 321, in _process_flow
self.state.delete_flow(f)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 584, in delete_flow
self.flows._remove(f)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 496, in _remove
self._list.remove(f)
ValueError: list.remove(x): x not in list
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 121, in handle
root_layer()
TypeError: 'NoneType' object is not callable

mitmproxy has crashed!
Please lodge a bug report at: https://github.com/mitmproxy/mitmproxy
----------------------------------------
Error in processing of request from 127.0.0.1:41084
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/netlib/tcp.py", line 854, in connection_thread
self.handle_client_connection(connection, client_address)
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 64, in handle_client_connection
h.handle()
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 152, in handle
self.channel.tell("clientdisconnect", root_layer)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 68, in tell
m.reply = DummyReply()
AttributeError: 'NoneType' object has no attribute 'reply'

# Fixed code
def __call__(self, *args):
    if self.master_reply is None:
        self.master_reply = args
        self.script_thread.start()
        return
    self.reply_func(*args)
# Buggy code
def __getattr__(self, k):
    return getattr(self.original_reply, k)


# Traceback (ValueError)
Error: Connection killed
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/venv/bin/mitmdump", line 9, in <module>
load_entry_point('mitmproxy', 'console_scripts', 'mitmdump')()
File "/home/christofferqa/mitmproxy/mitmproxy/main.py", line 102, in mitmdump
master.run()
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 354, in run
return flow.FlowMaster.run(self)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 128, in run
self.tick(self.masterq, 0.1)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 828, in tick
return super(FlowMaster, self).tick(q, timeout)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 113, in tick
self.handle(*msg)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 135, in handle
m(obj)
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 337, in handle_response
self._process_flow(f)
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 321, in _process_flow
self.state.delete_flow(f)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 584, in delete_flow
self.flows._remove(f)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 496, in _remove
self._list.remove(f)
ValueError: list.remove(x): x not in list
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 121, in handle
root_layer()
TypeError: 'NoneType' object is not callable

mitmproxy has crashed!
Please lodge a bug report at: https://github.com/mitmproxy/mitmproxy
----------------------------------------
Error in processing of request from 127.0.0.1:41084
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/netlib/tcp.py", line 854, in connection_thread
self.handle_client_connection(connection, client_address)
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 64, in handle_client_connection
h.handle()
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 152, in handle
self.channel.tell("clientdisconnect", root_layer)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 68, in tell
m.reply = DummyReply()
AttributeError: 'NoneType' object has no attribute 'reply'

# Fixed code
def __getattr__(self, k):
    return getattr(self.reply_func, k)
# Buggy code
def run():
    fn(*args, **kwargs)
    # If the script did not call .reply(), we have to do it now.
    reply_proxy()


# Traceback (ValueError)
Error: Connection killed
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/venv/bin/mitmdump", line 9, in <module>
load_entry_point('mitmproxy', 'console_scripts', 'mitmdump')()
File "/home/christofferqa/mitmproxy/mitmproxy/main.py", line 102, in mitmdump
master.run()
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 354, in run
return flow.FlowMaster.run(self)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 128, in run
self.tick(self.masterq, 0.1)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 828, in tick
return super(FlowMaster, self).tick(q, timeout)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 113, in tick
self.handle(*msg)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 135, in handle
m(obj)
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 337, in handle_response
self._process_flow(f)
File "/home/christofferqa/mitmproxy/mitmproxy/dump.py", line 321, in _process_flow
self.state.delete_flow(f)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 584, in delete_flow
self.flows._remove(f)
File "/home/christofferqa/mitmproxy/mitmproxy/flow.py", line 496, in _remove
self._list.remove(f)
ValueError: list.remove(x): x not in list
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 121, in handle
root_layer()
TypeError: 'NoneType' object is not callable

mitmproxy has crashed!
Please lodge a bug report at: https://github.com/mitmproxy/mitmproxy
----------------------------------------
Error in processing of request from 127.0.0.1:41084
Traceback (most recent call last):
File "/home/christofferqa/mitmproxy/netlib/tcp.py", line 854, in connection_thread
self.handle_client_connection(connection, client_address)
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 64, in handle_client_connection
h.handle()
File "/home/christofferqa/mitmproxy/mitmproxy/proxy/server.py", line 152, in handle
self.channel.tell("clientdisconnect", root_layer)
File "/home/christofferqa/mitmproxy/mitmproxy/controller.py", line 68, in tell
m.reply = DummyReply()
AttributeError: 'NoneType' object has no attribute 'reply'

# Fixed code
def run():
    fn(*args, **kwargs)
    # If the script did not call .reply(), we have to do it now.
    reply_proxy.done()
# Buggy code
def keypress(self, size, key):
    key = common.shortcuts(key)
    if key == "q":
        self.master.statusbar = self.state[0]
        self.master.body = self.state[1]
        self.master.header = self.state[2]
        self.master.make_view()
        return None
    elif key == "?":
        key = None
    return urwid.ListBox.keypress(self, size, key)


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/legend/mitmproxy/libmproxy/console/__init__.py", line 805, in run
self.loop.run()
File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 278, in run
self._run()
File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 375, in _run
self.event_loop.run()
File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 678, in run
self._loop()
File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 715, in _loop
self._watch_files[fd]()
File "/usr/lib/python2.7/site-packages/urwid/raw_display.py", line 392, in <lambda>
event_loop, callback, self.get_available_raw_input())
File "/usr/lib/python2.7/site-packages/urwid/raw_display.py", line 492, in parse_input
callback(processed, processed_codes)
File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 396, in _update
keys = self.input_filter(keys, raw)
File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 535, in input_filter
return self._input_filter(keys, raw)
File "/home/legend/mitmproxy/libmproxy/console/__init__.py", line 616, in input_filter
elif k in self.onekey:
TypeError: 'in <string>' requires string as left operand, not tuple

mitmproxy has crashed!
Please lodge a bug report at:
https://github.com/mitmproxy/mitmproxy
Shutting down...

# Fixed code
def keypress(self, size, key):
    key = common.shortcuts(key)
    if key == "q":
        self.master.statusbar = self.state[0]
        self.master.body = self.state[1]
        self.master.header = self.state[2]
        self.master.loop.widget = self.master.make_view()
        return None
    elif key == "?":
        key = None
    return urwid.ListBox.keypress(self, size, key)
# Buggy code
def response_closure(module, question, responses):
    resp_gen = ("%s\n" % to_text(r).rstrip("\n") for r in responses)

    def wrapped(info):
        try:
            return next(resp_gen)
        except StopIteration:
            module.fail_json(
                msg="No remaining responses for '%s', "
                "output was '%s'" % (question, info["child_result_list"][-1])
            )

    return wrapped


# Traceback (nUnicodeDecodeError)
fatal: [10.135.232.213]: FAILED! => {"changed": false, "failed": true,
"invocation": {"module_name": "expect"}, "module_stderr": "",
"module_stdout": "Traceback (most recent call last):\r\n  File
\"/tmp/ansible_V_modk/ansible_module_expect.py\", line 230, in <module>\r\n
main()\r\n  File \"/tmp/ansible_V_modk/ansible_module_expect.py\", line 199,
in main\r\n    events=events, cwd=chdir, echo=echo)\r\n  File
\"/usr/lib/python2.6/site-packages/pexpect/__init__.py\", line 225, in
runu\r\n    env=env, _spawn=spawnu, **kwargs)\r\n  File
\"/usr/lib/python2.6/site-packages/pexpect/__init__.py\", line 246, in
_run\r\n    index = child.expect(patterns)\r\n  File
\"/usr/lib/python2.6/site-packages/pexpect/__init__.py\", line 1451, in
expect\r\n    timeout, searchwindowsize)\r\n  File
\"/usr/lib/python2.6/site-packages/pexpect/__init__.py\", line 1466, in
expect_list\r\n    timeout, searchwindowsize)\r\n  File
\"/usr/lib/python2.6/site-packages/pexpect/__init__.py\", line 1535, in
expect_loop\r\n    c = self.read_nonblocking(self.maxread, timeout)\r\n
File \"/usr/lib/python2.6/site-packages/pexpect/__init__.py\", line 984, in
read_nonblocking\r\n    s = self._coerce_read_string(s)\r\n  File
\"/usr/lib/python2.6/site-packages/pexpect/__init__.py\", line 1797, in
_coerce_read_string\r\n    return self._decoder.decode(s, final=False)\r\n
File \"/usr/lib64/python2.6/codecs.py\", line 296, in decode\r\n
(result, consumed) = self._buffer_decode(data, self.errors,
final)\r\nUnicodeDecodeError: 'utf8' codec can't decode byte 0xd2 in
position 1166: invalid continuation byte\r\n", "msg": "MODULE FAILURE",
"parsed": false}

# Fixed code
def response_closure(module, question, responses):
    resp_gen = (b"%s\n" % to_bytes(r).rstrip(b"\n") for r in responses)

    def wrapped(info):
        try:
            return next(resp_gen)
        except StopIteration:
            module.fail_json(
                msg="No remaining responses for '%s', "
                "output was '%s'" % (question, info["child_result_list"][-1])
            )

    return wrapped
# Buggy code
def results_thread_main(strategy):
    while True:
        try:
            result = strategy._final_q.get()
            if isinstance(result, StrategySentinel):
                break
            else:
                strategy._results_lock.acquire()
                # only handlers have the listen attr, so this must be a handler
                # we split up the results into two queues here to make sure
                # handler and regular result processing don't cross wires
                if "listen" in result._task_fields:
                    strategy._handler_results.append(result)
                else:
                    strategy._results.append(result)
                strategy._results_lock.release()
        except (IOError, EOFError):
            break
        except Queue.Empty:
            pass


# Traceback (AttributeError)
Traceback (most recent call last):
File "/bin/ansible-playbook", line 123, in <module>
exit_code = cli.run()
File "/usr/lib/python3.6/site-packages/ansible/cli/playbook.py", line 127, in run
results = pbex.run()
File "/usr/lib/python3.6/site-packages/ansible/executor/playbook_executor.py", line 169, in run
result = self._tqm.run(play=play)
File "/usr/lib/python3.6/site-packages/ansible/executor/task_queue_manager.py", line 241, in run
play_return = strategy.run(iterator, play_context)
File "/usr/lib/python3.6/site-packages/ansible/plugins/strategy/linear.py", line 325, in run
results += self._wait_on_pending_results(iterator)
File "/usr/lib/python3.6/site-packages/ansible/plugins/strategy/__init__.py", line 764, in _wait_on_pending_results
results = self._process_pending_results(iterator)
File "/usr/lib/python3.6/site-packages/ansible/plugins/strategy/__init__.py", line 110, in inner
results = func(self, iterator, one_pass=one_pass, max_passes=max_passes)
File "/usr/lib/python3.6/site-packages/ansible/plugins/strategy/__init__.py", line 487, in _process_pending_results
original_host = get_original_host(task_result._host)
AttributeError: 'Block' object has no attribute '_host'

# Fixed code
def results_thread_main(strategy):
    while True:
        try:
            result = strategy._final_q.get()
            if isinstance(result, StrategySentinel):
                break
            elif isinstance(result, TaskResult):
                with strategy._results_lock:
                    # only handlers have the listen attr, so this must be a handler
                    # we split up the results into two queues here to make sure
                    # handler and regular result processing don't cross wires
                    if "listen" in result._task_fields:
                        strategy._handler_results.append(result)
                    else:
                        strategy._results.append(result)
            else:
                display.warning(
                    "Received an invalid object (%s) in the result queue: %r"
                    % (type(result), result)
                )
        except (IOError, EOFError):
            break
        except Queue.Empty:
            pass
# Buggy code
def remove(self, path, recurse=False):
    path = self._escape(self._unquote(path))
    if recurse:
        return self._encode_script("""Remove-Item "%s" -Force -Recurse;""" % path)
    else:
        return self._encode_script("""Remove-Item "%s" -Force;""" % path)


# Traceback (OSError)
TASK [fetch log files] ***********************************************************************************************************************************************************************
task path: /home/testuser/ansible/test.yml:12
Using module file /usr/local/ansible/2.7/lib/python3.6/site-packages/ansible/modules/windows/win_stat.ps1
<testclient> ESTABLISH WINRM CONNECTION FOR USER: testuser@DOMAIN on PORT 5985 TO testclient
checking if winrm_host testclient is an IPv6 address
EXEC (via pipeline wrapper)
<testclient> FETCH "C:\Temp\testfile_with_$dollar.txt" TO "/home/testuser/ansible/testfile_with_$dollar.txt"
Traceback (most recent call last):
File "/usr/local/ansible/2.7/lib/python3.6/site-packages/ansible/plugins/connection/winrm.py", line 681, in fetch_file
raise IOError(to_native(result.std_err))
OSError: #< CLIXML
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><S S="Error">The variable '$dollar' cannot be retrieved because it has not been set._x000D__x000A_</S><S S="Error">At line:2 char:32_x000D__x000A_</S><S S="Error">+ $path = "C:\Temp\testfile_with_$dollar.txt"_x000D__x000A_</S><S S="Error">+                                ~~~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : InvalidOperation: (dollar:String) [], RuntimeExc _x000D__x000A_</S><S S="Error">   eption_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : VariableIsUndefined_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S><S S="Error">The variable '$path' cannot be retrieved because it has not been set._x000D__x000A_</S><S S="Error">At line:3 char:21_x000D__x000A_</S><S S="Error">+ If (Test-Path -Path $path -PathType Leaf)_x000D__x000A_</S><S S="Error">+                     ~~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : InvalidOperation: (path:String) [], RuntimeExcep _x000D__x000A_</S><S S="Error">   tion_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : VariableIsUndefined_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>
fatal: [testclient]: FAILED! => {}

# Fixed code
def remove(self, path, recurse=False):
    path = self._escape(self._unquote(path))
    if recurse:
        return self._encode_script("""Remove-Item '%s' -Force -Recurse;""" % path)
    else:
        return self._encode_script("""Remove-Item '%s' -Force;""" % path)