Commit 9c99bbcd authored by Julian Andres Klode's avatar Julian Andres Klode

apt_pkg.DepCache: Raise CacheMismatchError if argument belongs to diff. cache

This allows us to catch errors and recover from them.
parent e918f14c
......@@ -32,6 +32,9 @@ Exceptions
----------
.. autoclass:: Error
.. autoclass:: CacheMismatchError
Working with the cache
----------------------
.. class:: Cache([progress: apt.progress.base.OpProgress])
......@@ -208,6 +211,9 @@ Managing the cache with :class:`DepCache`
method is expected to raise an exception, it will be stated in the
description.
If an object of a different cache is passed, :class:`CacheMismatchError`
is raised.
.. method:: commit(acquire_progress, install_progress)
Commit all marked changes, while reporting the progress of
......
......@@ -45,6 +45,13 @@ static char PyAptError_Doc[] =
PyObject *PyAptError;
static char PyAptCacheMismatchError_Doc[] =
"Raised when passing an object from a different cache to\n"
":class:`apt_pkg.DepCache` methods\n\n"
".. versionadded:: 1.6.1";
PyObject *PyAptCacheMismatchError;
/**
* A Python->C->Python gettext() function.
*
......@@ -813,6 +820,10 @@ extern "C" void initapt_pkg()
if (PyAptError == NULL)
INIT_ERROR;
PyAptCacheMismatchError = PyErr_NewExceptionWithDoc("apt_pkg.CacheMismatchError", PyAptCacheMismatchError_Doc, PyExc_ValueError, NULL);
if (PyAptCacheMismatchError == NULL)
INIT_ERROR;
// Initialize the module
#if PY_MAJOR_VERSION >= 3
PyObject *Module = PyModule_Create(&moduledef);
......@@ -827,6 +838,7 @@ extern "C" void initapt_pkg()
Config->NoDelete = true;
PyModule_AddObject(Module,"config",Config);
PyModule_AddObject(Module,"Error",PyAptError);
PyModule_AddObject(Module,"CacheMismatchError", PyAptCacheMismatchError);
......
......@@ -36,7 +36,7 @@
#define VALIDATE_ITERATOR(I) do { \
if ((I).Cache() != &depcache->GetCache()) { \
PyErr_SetString(PyExc_ValueError, "Object of different cache passed as argument to apt_pkg.DepCache method"); \
PyErr_SetString(PyAptCacheMismatchError, "Object of different cache passed as argument to apt_pkg.DepCache method"); \
return nullptr; \
} \
} while(0)
......
......@@ -36,6 +36,10 @@
* Exception class for almost all Python errors
*/
extern PyObject *PyAptError;
/**
* Exception class for invalidated cache objects.
*/
extern PyObject *PyAptCacheMismatchError;
#if PYTHON_API_VERSION < 1013
typedef int Py_ssize_t;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment