From: Michael Tremer Date: Fri, 19 Aug 2022 13:57:03 +0000 (+0000) Subject: python: Add exceptions for check operation X-Git-Tag: 0.9.28~424 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6713d0dfacb9366e62f06d80ac37d37d003b8ddc;p=pakfire.git python: Add exceptions for check operation Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/_pakfiremodule.c b/src/_pakfire/_pakfiremodule.c index 92cd54cba..b00b000de 100644 --- a/src/_pakfire/_pakfiremodule.c +++ b/src/_pakfire/_pakfiremodule.c @@ -41,6 +41,9 @@ PyObject* PyExc_BadSignatureError; PyObject* PyExc_CommandExecutionError; PyObject* PyExc_DependencyError; +PyObject* PyExc_CheckError; +PyObject* PyExc_CheckFileVerificationError; + static PyObject* _pakfire_native_arch(void) { const char* arch = pakfire_arch_native(); if (!arch) @@ -85,6 +88,31 @@ PyMODINIT_FUNC PyInit__pakfire(void) { Py_INCREF(PyExc_DependencyError); PyModule_AddObject(module, "DependencyError", PyExc_DependencyError); + // Check Exceptions + + // CheckError + PyExc_CheckError = PyErr_NewException("_pakfire.CheckError", NULL, NULL); + Py_INCREF(PyExc_CheckError); + if (PyModule_AddObject(module, "CheckError", PyExc_CheckError) < 0) { + Py_XDECREF(PyExc_CheckError); + Py_CLEAR(PyExc_CheckError); + goto ERROR; + } + + // CheckFileVerificationError based on CheckError + PyExc_CheckFileVerificationError = PyErr_NewExceptionWithDoc( + "_pakfire.CheckFileVerificationError", + "The file verification process failed", + PyExc_CheckError, + NULL + ); + Py_INCREF(PyExc_CheckFileVerificationError); + if (PyModule_AddObject(module, "CheckFileVerificationError", PyExc_CheckFileVerificationError) < 0) { + Py_XDECREF(PyExc_CheckFileVerificationError); + Py_CLEAR(PyExc_CheckFileVerificationError); + goto ERROR; + } + // Add digest constants if (PyModule_AddIntMacro(module, PAKFIRE_DIGEST_SHA512)) return NULL; @@ -153,4 +181,9 @@ PyMODINIT_FUNC PyInit__pakfire(void) { PyModule_AddObject(module, "Solution", (PyObject *)&SolutionType); return module; + +ERROR: + Py_DECREF(module); + + return NULL; } diff --git a/src/_pakfire/errors.h b/src/_pakfire/errors.h index 52a52e896..f1f5d465b 100644 --- a/src/_pakfire/errors.h +++ b/src/_pakfire/errors.h @@ -28,4 +28,7 @@ extern PyObject* PyExc_BadSignatureError; extern PyObject* PyExc_CommandExecutionError; extern PyObject* PyExc_DependencyError; +extern PyObject* PyExc_CheckError; +extern PyObject* PyExc_CheckFileVerificationError; + #endif /* PYTHON_PAKFIRE_ERRORS_H */