[py] improve digital_filter error messages (closes #gh-241)
authorPaul Brossier <piem@piem.org>
Tue, 26 Mar 2019 14:17:05 +0000 (15:17 +0100)
committerPaul Brossier <piem@piem.org>
Tue, 26 Mar 2019 14:17:05 +0000 (15:17 +0100)
python/ext/py-filter.c

index 861f8cd..8eb87aa 100644 (file)
@@ -156,8 +156,10 @@ Py_filter_set_c_weighting (Py_filter * self, PyObject *args)
 
   err = aubio_filter_set_c_weighting (self->o, samplerate);
   if (err > 0) {
 
   err = aubio_filter_set_c_weighting (self->o, samplerate);
   if (err > 0) {
-    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");
+    }
     return NULL;
   }
   Py_RETURN_NONE;
     return NULL;
   }
   Py_RETURN_NONE;
@@ -174,8 +176,10 @@ Py_filter_set_a_weighting (Py_filter * self, PyObject *args)
 
   err = aubio_filter_set_a_weighting (self->o, samplerate);
   if (err > 0) {
 
   err = aubio_filter_set_a_weighting (self->o, samplerate);
   if (err > 0) {
-    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");
+    }
     return NULL;
   }
   Py_RETURN_NONE;
     return NULL;
   }
   Py_RETURN_NONE;
@@ -192,8 +196,10 @@ Py_filter_set_biquad(Py_filter * self, PyObject *args)
 
   err = aubio_filter_set_biquad (self->o, b0, b1, b2, a1, a2);
   if (err > 0) {
 
   err = aubio_filter_set_biquad (self->o, b0, b1, b2, a1, a2);
   if (err > 0) {
-    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");
+    }
     return NULL;
   }
   Py_RETURN_NONE;
     return NULL;
   }
   Py_RETURN_NONE;