solver/dnf5.py: fix depsolve MarkingErrors

A wrong exception type was returned for the same kind of issues,
compared to the DNF4 version. Specifically, the DNF4 version returned
`MarkingErrors`, while the DNF5 version returned `DepsolveError`, when
a non-existent package was specified in the depsplve request. Make the
behavior consistent and return `MarkingErrors` also from the DNF5
version.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2024-08-05 15:47:57 +02:00 committed by Tomáš Hozza
parent cdde20385d
commit 1c4ec8faa3

View file

@ -6,11 +6,12 @@ from typing import List
import libdnf5 as dnf5
from libdnf5.base import GoalProblem_NO_PROBLEM as NO_PROBLEM
from libdnf5.base import GoalProblem_NOT_FOUND as NOT_FOUND
from libdnf5.common import QueryCmp_CONTAINS as CONTAINS
from libdnf5.common import QueryCmp_EQ as EQ
from libdnf5.common import QueryCmp_GLOB as GLOB
from osbuild.solver import DepsolveError, RepoError, SolverBase, modify_rootdir_path, read_keys
from osbuild.solver import DepsolveError, MarkingError, RepoError, SolverBase, modify_rootdir_path, read_keys
def remote_location(package, schemes=("http", "ftp", "file", "https")):
@ -375,7 +376,11 @@ class DNF5(SolverBase):
for pkg in transaction.get("package-specs"):
goal.add_install(pkg, settings)
transaction = goal.resolve()
if transaction.get_problems() != NO_PROBLEM:
transaction_problems = transaction.get_problems()
if transaction_problems == NOT_FOUND:
raise MarkingError("\n".join(transaction.get_resolve_logs_as_strings()))
if transaction_problems != NO_PROBLEM:
raise DepsolveError("\n".join(transaction.get_resolve_logs_as_strings()))
# store the current transaction result