Better debugging for exec / json parsing
Closed this issue · 1 comments
While debugging the exec issue in #248 I've mostly been greeted by generic JSON parse errors.
I would have expected some debug output about the actual issue.
Examples of failing code paths:
lnnode.py
def getnewaddress(self):
res = json.loads(self.lncli("newaddress p2wkh"))
return res["address"]
ln_test.py
inv = json.loads(base.warcli("lncli 2 addinvoice --amt=1234"))["payment_request"]
To improve debugging it would be great to have a "execute + parse json" method that
- runs the command
- tries to parse the output
- on error: log the command + output and re-throw an error
Alternately it could be added to all code paths, but given that json output is the most common output I would expect it to be very redundant.
Seems like we could use a decorator for this, similar to @exponential_backoff
. What I'm envisioning is a pattern where functions return un-parsed outputs and then we add a decorator for parsing the output and catching any errors. We could add specific decorators for different output types, but starting with a @parse_json_response
decorator seems like a good start.