]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
_pakfire: Improve Python exception raising on build
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 Apr 2023 15:27:07 +0000 (15:27 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 Apr 2023 15:27:07 +0000 (15:27 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c

index b6dfa3a762025e6be9ae4b36cceed26d8b32afc9..80f3c5ce50f9261407d2cb65a7097cec0f7a1afb 100644 (file)
@@ -1251,30 +1251,53 @@ static PyObject* Pakfire_build(PakfireObject* self, PyObject* args, PyObject* kw
        if (disable_tests)
                flags |= PAKFIRE_BUILD_DISABLE_TESTS;
 
-       Py_BEGIN_ALLOW_THREADS
-
        // Create a new build environment
        r = pakfire_build_create(&build, self->pakfire, build_id, flags);
-       if (r)
+       if (r) {
+               PyErr_SetFromErrno(PyExc_OSError);
                goto ERROR;
+       }
 
        // Set target
        if (target) {
                r = pakfire_build_set_target(build, target);
-               if (r)
+               if (r) {
+                       PyErr_SetFromErrno(PyExc_OSError);
                        goto ERROR;
+               }
        }
 
+       Py_BEGIN_ALLOW_THREADS
+
        // Run build
        r = pakfire_build_exec(build, path);
+       if (r) {
+               Py_BLOCK_THREADS;
+
+               if (r < 0) {
+                       PyErr_SetFromErrno(PyExc_OSError);
+
+               // Raise a command execution error
+               } else {
+                       PyObject* code = PyLong_FromLong(r);
+
+                       PyErr_SetObject(PyExc_CommandExecutionError, code);
+                       Py_DECREF(code);
+               }
+
+               goto ERROR;
+       }
+
+       Py_END_ALLOW_THREADS
 
 ERROR:
        if (build)
                pakfire_build_unref(build);
 
-       Py_END_ALLOW_THREADS
+       if (r)
+               return NULL;
 
-       return execute_return_value(r);
+       Py_RETURN_NONE;
 }
 
 static PyObject* Pakfire_shell(PakfireObject* self, PyObject* args, PyObject* kwargs) {