Cleanup exception handling
This commit is contained in:
@@ -10,28 +10,26 @@ extern "C" {
|
||||
PyObject * wrap_kj_exception(kj::Exception &);
|
||||
}
|
||||
|
||||
void check_py_error() {
|
||||
PyObject * err = PyErr_Occurred();
|
||||
if(err) {
|
||||
// PyErr_Clear();
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
PyObject * wrapPyFunc(PyObject * func, PyObject * arg) {
|
||||
PyObject * result = PyObject_CallFunctionObjArgs(func, arg, NULL);
|
||||
Py_DECREF(func);
|
||||
|
||||
PyObject * err = PyErr_Occurred();
|
||||
if(err) {
|
||||
char * errorMsg = PyString_AsString(PyObject_Repr(err));
|
||||
// PyErr_Clear();
|
||||
throw std::invalid_argument(errorMsg);
|
||||
}
|
||||
check_py_error();
|
||||
return result;
|
||||
}
|
||||
|
||||
void wrapRemoteCall(PyObject * func, capnp::Response<capnp::DynamicStruct> & arg) {
|
||||
wrap_remote_call(func, arg);
|
||||
|
||||
PyObject * err = PyErr_Occurred();
|
||||
if(err) {
|
||||
char * errorMsg = PyString_AsString(PyObject_Repr(err));
|
||||
// PyErr_Clear();
|
||||
throw std::invalid_argument(errorMsg);
|
||||
}
|
||||
check_py_error();
|
||||
}
|
||||
|
||||
::kj::Promise<PyObject *> evalLater(kj::EventLoop & loop, PyObject * func) {
|
||||
@@ -81,15 +79,7 @@ public:
|
||||
|
||||
kj::Promise<void> * promise = call_server_method(py_server, const_cast<char *>(methodName.cStr()), context);
|
||||
|
||||
PyObject * err = PyErr_Occurred();
|
||||
if(err) {
|
||||
PyObject *ptype, *pvalue, *ptraceback;
|
||||
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
|
||||
|
||||
char * errorMsg = PyString_AsString(pvalue);
|
||||
PyErr_Clear();
|
||||
throw std::invalid_argument(errorMsg);
|
||||
}
|
||||
check_py_error();
|
||||
|
||||
if(promise == nullptr)
|
||||
return kj::READY_NOW;
|
||||
|
||||
@@ -113,7 +113,7 @@ def test_exception_client(capability):
|
||||
client = capability.TestInterface.new_client(BadServer(), loop)
|
||||
|
||||
remote = client._send('foo', i=5)
|
||||
with pytest.raises(RuntimeError):
|
||||
with pytest.raises(ValueError):
|
||||
loop.wait_remote(remote)
|
||||
|
||||
class BadPipelineServer:
|
||||
@@ -137,7 +137,7 @@ def test_exception_chain(capability):
|
||||
try:
|
||||
loop.wait_remote(remote)
|
||||
except Exception as e:
|
||||
assert e.message == 'test'
|
||||
assert str(e) == 'test'
|
||||
|
||||
def test_pipeline_exception(capability):
|
||||
loop = capnp.EventLoop()
|
||||
|
||||
Reference in New Issue
Block a user