Skip to content

Commit 1ccd8f0

Browse files
daveyarwoodSevereOverfl0w
authored andcommitted
catch BrokenPipeError and handle with a provided callback
1 parent 61e00a9 commit 1ccd8f0

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

pythonx/async_clj_omni/cider.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ def candidate(val):
2929
"menu": " ".join(arglists) if arglists else ""
3030
}
3131

32+
def rethrow(e):
33+
raise e
3234

33-
def cider_gather(logger, nrepl, keyword, session, ns):
35+
def cider_gather(logger, nrepl, keyword, session, ns, on_error=rethrow):
3436
# Should be unique for EVERY message
3537
msgid = uuid.uuid4().hex
3638

@@ -50,15 +52,18 @@ def completion_callback(cmsg, cwc, ckey):
5052

5153
logger.debug("cider_gather watching msgid")
5254

53-
# TODO: context for context aware completions
54-
nrepl.send({
55-
"id": msgid,
56-
"op": "complete",
57-
"session": session,
58-
"symbol": keyword,
59-
"extra-metadata": ["arglists", "doc"],
60-
"ns": ns
61-
})
55+
try:
56+
# TODO: context for context aware completions
57+
nrepl.send({
58+
"id": msgid,
59+
"op": "complete",
60+
"session": session,
61+
"symbol": keyword,
62+
"extra-metadata": ["arglists", "doc"],
63+
"ns": ns
64+
})
65+
except BrokenPipeError as e:
66+
on_error(e)
6267

6368
completion_event.wait(0.5)
6469

pythonx/async_clj_omni/fireplace.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ def global_watch(cmsg, cwc, ckey):
4545

4646
return self.__conns.get(conn_string)
4747

48+
def remove_conn(self, conn_string):
49+
self.logger.debug(
50+
("Connection to {} died. "
51+
"Removing the connection.").format(conn_string)
52+
)
53+
self.__conns.pop(conn_string, None)
54+
4855
class Fireplace_nrepl:
4956
def __init__(self, wc):
5057
self.wc = wc
@@ -80,8 +87,12 @@ def gather_candidates(self, complete_str):
8087

8188
wc = self.__connmanager.get_conn(conn_string)
8289

90+
def on_error(e):
91+
self.__connmanager.remove_conn(conn_string)
92+
8393
return cider_gather(self.__logger,
8494
Fireplace_nrepl(wc),
8595
complete_str,
8696
connection.get("session"),
87-
ns)
97+
ns,
98+
on_error)

0 commit comments

Comments
 (0)