Skip to content

Commit

Permalink
fixup! pyln: Plugin methods and hooks refuse to set results twice
Browse files Browse the repository at this point in the history
  • Loading branch information
m-schmoock committed Sep 26, 2020
1 parent db7f6cd commit a2a64a3
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions contrib/pyln-client/pyln/client/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, plugin: 'Plugin', req_id: Optional[int], method: str,
self.plugin = plugin
self.state = RequestState.PENDING
self.id = req_id
self.termination_tb: Optional[traceback.StackSummary] = None
self.termination_tb: Optional[str] = None

def getattr(self, key: str) -> Union[Method, Any, int]:
if key == "params":
Expand All @@ -86,36 +86,26 @@ def getattr(self, key: str) -> Union[Method, Any, int]:
def set_result(self, result: Any) -> None:
if self.state != RequestState.PENDING:
assert(self.termination_tb is not None)
frames = self.termination_tb.format()
tb = "".join(frames[:-1])
raise ValueError(
"Cannot set the result of a request that is not pending, "
"current state is {state}. Request previously terminated at\n"
"{tb}".format(
state=self.state,
tb=tb
))
"{tb}".format(state=self.state, tb=self.termination_tb))
self.result = result
self._write_result({
'jsonrpc': '2.0',
'id': self.id,
'result': self.result
})
self.state = RequestState.FINISHED
self.termination_tb = traceback.extract_stack()
self.termination_tb = "".join(traceback.extract_stack().format()[:-1])

def set_exception(self, exc: Exception) -> None:
if self.state != RequestState.PENDING:
assert(self.termination_tb is not None)
frames = self.termination_tb.format()
tb = "".join(frames[:-1])
raise ValueError(
"Cannot set the exception of a request that is not pending, "
"current state is {state}. Request previously terminated at\n"
"{tb}".format(
state=self.state,
tb=tb
))
"{tb}".format(state=self.state, tb=self.termination_tb))
self.exc = exc
self._write_result({
'jsonrpc': '2.0',
Expand All @@ -129,7 +119,7 @@ def set_exception(self, exc: Exception) -> None:
},
})
self.state = RequestState.FAILED
self.termination_tb = traceback.extract_stack()
self.termination_tb = "".join(traceback.extract_stack().format()[:-1])

def _write_result(self, result: dict) -> None:
self.plugin._write_locked(result)
Expand Down

0 comments on commit a2a64a3

Please sign in to comment.