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