commit:     0855821572f32e81b031a250f7491f34a2fd4078
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 24 23:29:29 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Feb 25 08:24:55 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=08558215

dbapi: Fix TypeError when passing Exception to warnings.warn

If an Exception is passed as a message to warnings.warn then
it triggers this TypeError:

            if metadata_updates:
                try:
                    aux_update(cpv, metadata_updates)
                except (InvalidBinaryPackageFormat, CorruptionKeyError) as e:
>                   warnings.warn(e)
E                   TypeError: expected string or bytes-like object, got 
'CorruptionKeyError'

Fixes: fb1d0a22f657 ("dbapi: KeyError tolerance during package moves")
Bug: https://bugs.gentoo.org/922935
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
Closes: https://github.com/gentoo/portage/pull/1282
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/dbapi/__init__.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/portage/dbapi/__init__.py b/lib/portage/dbapi/__init__.py
index 6f95b93a21..9105227c77 100644
--- a/lib/portage/dbapi/__init__.py
+++ b/lib/portage/dbapi/__init__.py
@@ -1,11 +1,12 @@
-# Copyright 1998-2023 Gentoo Authors
+# Copyright 1998-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 __all__ = ["dbapi"]
 
 import functools
+import logging
 import re
-import warnings
+import sys
 from typing import Any, Dict, List, Optional, Tuple
 from collections.abc import Sequence
 
@@ -429,7 +430,9 @@ class dbapi:
                 try:
                     aux_update(cpv, metadata_updates)
                 except (InvalidBinaryPackageFormat, CorruptionKeyError) as e:
-                    warnings.warn(e)
+                    logging.warning(
+                        f"{e.__class__.__name__}: {e}", exc_info=sys.exc_info()
+                    )
                 if onUpdate:
                     onUpdate(maxval, i + 1)
             if onProgress:
@@ -477,6 +480,6 @@ class dbapi:
             try:
                 self.aux_update(mycpv, mydata)
             except CorruptionKeyError as e:
-                warnings.warn(e)
+                logging.warning(f"{e.__class__.__name__}: {e}", 
exc_info=sys.exc_info())
                 continue
         return moves

Reply via email to