forked from M-Labs/artiq
1
0
Fork 0

pc_rpc: report exception traceback

This commit is contained in:
Sebastien Bourdeauducq 2014-10-25 11:31:54 +08:00
parent a0ea83c98a
commit f106b238eb
1 changed files with 5 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import socket
import json
import asyncio
import traceback
class RemoteError(Exception):
@ -29,7 +30,7 @@ class Client:
if obj["result"] == "ok":
return obj["ret"]
elif obj["result"] == "error":
raise RemoteError(obj["message"])
raise RemoteError(obj["message"] + "\n" + obj["traceback"])
else:
raise ValueError
@ -81,8 +82,9 @@ class Server:
obj = {"result": "ok", "ret": ret}
except Exception as e:
obj = {"result": "error",
"message": type(e).__name__ + ": " + str(e)}
line = json.dumps(obj) + "\n"
"message": type(e).__name__ + ": " + str(e),
"traceback": traceback.format_exc()}
line = pyon.encode(obj) + "\n"
writer.write(line.encode())
finally:
writer.close()