Deduplicate Error Messages
flyingsilverfin opened this issue · comments
Description
Right now, users of client-python always get a stacked error message:
In [14]: s.transaction().write()
---------------------------------------------------------------------------
_Rendezvous Traceback (most recent call last)
/usr/local/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py in send_receive(self, request)
208 self._add_request(request)
--> 209 response = next(self._response_iterator)
210 except Exception as e: # specialize into different gRPC exceptions?
/usr/local/lib/python3.7/site-packages/grpc/_channel.py in __next__(self)
387 def __next__(self):
--> 388 return self._next()
389
/usr/local/lib/python3.7/site-packages/grpc/_channel.py in _next(self)
381 elif self._state.code is not None:
--> 382 raise self
383
_Rendezvous: <_Rendezvous of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "grakn.core.kb.server.exception.SessionException-The client session with session ID [testing0037b22d-67ce-4df3-8ee3-2733989855ad] was not found. Create a new session to interact with the graph.. Please check server logs for the stack trace."
debug_error_string = "{"created":"@1591890637.307174000","description":"Error received from peer ipv6:[::1]:48555","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"grakn.core.kb.server.exception.SessionException-The client session with session ID [testing0037b22d-67ce-4df3-8ee3-2733989855ad] was not found. Create a new session to interact with the graph.. Please check server logs for the stack trace.","grpc_status":14}"
>
During handling of the above exception, another exception occurred:
GraknError Traceback (most recent call last)
<ipython-input-14-bad13dd12b5f> in <module>()
----> 1 s.transaction().write()
/usr/local/lib/python3.7/site-packages/grakn/client.py in write(self)
104
105 def write(self):
--> 106 transaction_service = TransactionService(self._session_id, _TxType.WRITE, self._transaction_rpc_constructor)
107 return Transaction(transaction_service)
108
/usr/local/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py in __init__(self, session_id, tx_type, transaction_endpoint)
37 # open the transaction with an 'open' message
38 open_req = RequestBuilder.open_tx(session_id, tx_type)
---> 39 self._communicator.send_receive(open_req)
40 __init__.__annotations__ = {'tx_type': enums.TxType}
41
/usr/local/lib/python3.7/site-packages/grakn/service/Session/TransactionService.py in send_receive(self, request)
211 # invalidate this communicator, functionally this occurs automatically on exception (iterator not usable anymore)
212 self._closed = True
--> 213 raise GraknError("Server/network error: {0}\n\n generated from request: {1}".format(e, request))
214
215 if response is None:
GraknError: Server/network error: <_Rendezvous of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "grakn.core.kb.server.exception.SessionException-The client session with session ID [testing0037b22d-67ce-4df3-8ee3-2733989855ad] was not found. Create a new session to interact with the graph.. Please check server logs for the stack trace."
debug_error_string = "{"created":"@1591890637.307174000","description":"Error received from peer ipv6:[::1]:48555","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"grakn.core.kb.server.exception.SessionException-The client session with session ID [testing0037b22d-67ce-4df3-8ee3-2733989855ad] was not found. Create a new session to interact with the graph.. Please check server logs for the stack trace.","grpc_status":14}"
>
generated from request: open_req {
sessionId: "testing0037b22d-67ce-4df3-8ee3-2733989855ad"
type: WRITE
}
Ideally, we would only throw a single exception with the server side exception/error message within it.
Environment
Grakn Core any version with any client-python since approx 1.4
Reproducible Steps
Cause any error in client-python
Expected Output
Single, neatly wrapped exception with the server's error
Actual Output
Two client-side stack traces! And buried within these are the server error message, duplicated twice.
Additional information
We could mirror the style of errors occuring in the server, where a specific class of RuntimeException is caught at the very top level of everything, and printed out without a stack trace, just error message.
This is still an issue in 2.0.0-alpha.
This is effectively resolved in 2.0.0 production. Errors from the server are printed out as GraknClientException, along with their underlying cause, which is currently always the gRPC error that was constructed by the server.
The cause is set to the __cause__ attribute of the GraknClientException, meaning we get a much cleaner stack trace where Python describes that:
The above exception was the direct cause of the following exception:
While this does still lead to some duplication in the error message, it feels much more "correct" and furthermore this duplication will go away when typedb/typedb#6146 is implemented.