[py] digital_filter.set_* raise ValueError (see #gh-241)
authorPaul Brossier <piem@piem.org>
Tue, 26 Mar 2019 14:22:37 +0000 (15:22 +0100)
committerPaul Brossier <piem@piem.org>
Tue, 26 Mar 2019 14:22:37 +0000 (15:22 +0100)
python/ext/py-filter.c

index 8eb87aa..19dcc60 100644 (file)
@@ -159,6 +159,11 @@ Py_filter_set_c_weighting (Py_filter * self, PyObject *args)
     if (PyErr_Occurred() == NULL) {
       PyErr_SetString (PyExc_ValueError,
           "error when setting filter to C-weighting");
     if (PyErr_Occurred() == NULL) {
       PyErr_SetString (PyExc_ValueError,
           "error when setting filter to C-weighting");
+    } else {
+      // change the RuntimeError into ValueError
+      PyObject *type, *value, *traceback;
+      PyErr_Fetch(&type, &value, &traceback);
+      PyErr_Restore(PyExc_ValueError, value, traceback);
     }
     return NULL;
   }
     }
     return NULL;
   }
@@ -179,6 +184,11 @@ Py_filter_set_a_weighting (Py_filter * self, PyObject *args)
     if (PyErr_Occurred() == NULL) {
       PyErr_SetString (PyExc_ValueError,
           "error when setting filter to A-weighting");
     if (PyErr_Occurred() == NULL) {
       PyErr_SetString (PyExc_ValueError,
           "error when setting filter to A-weighting");
+    } else {
+      // change the RuntimeError into ValueError
+      PyObject *type, *value, *traceback;
+      PyErr_Fetch(&type, &value, &traceback);
+      PyErr_Restore(PyExc_ValueError, value, traceback);
     }
     return NULL;
   }
     }
     return NULL;
   }
@@ -199,6 +209,11 @@ Py_filter_set_biquad(Py_filter * self, PyObject *args)
     if (PyErr_Occurred() == NULL) {
       PyErr_SetString (PyExc_ValueError,
           "error when setting filter with biquad coefficients");
     if (PyErr_Occurred() == NULL) {
       PyErr_SetString (PyExc_ValueError,
           "error when setting filter with biquad coefficients");
+    } else {
+      // change the RuntimeError into ValueError
+      PyObject *type, *value, *traceback;
+      PyErr_Fetch(&type, &value, &traceback);
+      PyErr_Restore(PyExc_ValueError, value, traceback);
     }
     return NULL;
   }
     }
     return NULL;
   }