Unify Python addInstall/Reinstall/Erase exception message format

addErase() claimed package not installed for failures, but there could
be other reasons, and for eg. headers coming from match iterators
failure to add cannot be "not installed".

Use a common message format that actually states which operation failed.
This commit is contained in:
Panu Matilainen 2020-06-04 10:44:11 +03:00 committed by Florian Festi
parent 869a36c172
commit 25e856a6d4
2 changed files with 9 additions and 6 deletions

View File

@ -72,13 +72,16 @@ class TransactionSet(TransactionSetCore):
upgrade = (how == "u")
if not TransactionSetCore.addInstall(self, header, key, upgrade):
raise rpm.error("adding package to transaction failed")
if upgrade:
raise rpm.error("adding upgrade to transaction failed")
else:
raise rpm.error("adding install to transaction failed")
def addReinstall(self, item, key):
header = self._f2hdr(item)
if not TransactionSetCore.addReinstall(self, header, key):
raise rpm.error("adding package to transaction failed")
raise rpm.error("adding reinstall to transaction failed")
def addErase(self, item):
hdrs = []
@ -95,7 +98,7 @@ class TransactionSet(TransactionSetCore):
for h in hdrs:
if not TransactionSetCore.addErase(self, h):
raise rpm.error("package not installed")
raise rpm.error("adding erasure to transaction failed")
# garbage collection should take care but just in case...
if isinstance(hdrs, rpm.mi):

View File

@ -264,13 +264,13 @@ ts = rpm.ts()
h = rpm.hdr()
h['name'] = "foo"
try:
ts.addInstall(h, 'foo', 'u')
ts.addInstall(h, 'foo', 'i')
except rpm.error as err:
myprint(err)
for e in ts:
myprint(e.NEVRA())
],
[adding package to transaction failed]
[adding install to transaction failed]
)
RPMPY_TEST([add bogus package to transaction 2],[
@ -291,7 +291,7 @@ except rpm.error as err:
for e in ts:
myprint(e.NEVRA())
],
[adding package to transaction failed]
[adding upgrade to transaction failed]
)
AT_SETUP([database iterators])