[py] use aubio_log message when set by failed aubio_<>_set_<>
authorPaul Brossier <piem@piem.org>
Tue, 30 Oct 2018 12:19:53 +0000 (13:19 +0100)
committerPaul Brossier <piem@piem.org>
Tue, 30 Oct 2018 12:19:53 +0000 (13:19 +0100)
python/lib/gen_code.py

index 7527fe9..1266336 100644 (file)
@@ -480,7 +480,14 @@ Pyaubio_{shortname}_set_{param} (Py_{shortname} *self, PyObject *args)
   err = aubio_{shortname}_set_{param} (self->o, {param});
 
   if (err > 0) {{
-    PyErr_SetString (PyExc_ValueError, "error running aubio_{shortname}_set_{param}");
+    if (PyErr_Occurred() == NULL) {{
+      PyErr_SetString (PyExc_ValueError, "error running aubio_{shortname}_set_{param}");
+    }} else {{
+      // change the RuntimeError into ValueError
+      PyObject *type, *value, *traceback;
+      PyErr_Fetch(&type, &value, &traceback);
+      PyErr_Restore(PyExc_ValueError, value, traceback);
+    }}
     return NULL;
   }}
   Py_RETURN_NONE;