public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] search._xmatch: handle aux_get KeyError (525718)
@ 2014-12-11  7:51 Zac Medico
  2014-12-11  8:08 ` Alexander Berntsen
  2014-12-11  8:33 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
  0 siblings, 2 replies; 4+ messages in thread
From: Zac Medico @ 2014-12-11  7:51 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

Since commit 55c8c8bc7a781e3f71ce92922eea64ad4cafce3c, emerge --search
can raise an unhandled KeyError if a pkg_desc_index contains a stale
package. Handle it with the same error message used for other aux_get
failures.

Fixes: 55c8c8bc7a78 ("Add emerge --search-index option.")
X-Gentoo-Bug: 525718
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=525718
---
 pym/_emerge/search.py | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/pym/_emerge/search.py b/pym/_emerge/search.py
index 90dbcec..76adcea 100644
--- a/pym/_emerge/search.py
+++ b/pym/_emerge/search.py
@@ -166,8 +166,14 @@ class search(object):
 				else:
 					db_keys = list(db._aux_cache_keys)
 					for cpv in db.match(atom):
-						metadata = zip(db_keys,
-							db.aux_get(cpv, db_keys))
+						try:
+							metadata = zip(db_keys,
+								db.aux_get(cpv, db_keys))
+						except KeyError:
+							portage.writemsg("emerge: search: "
+								"aux_get() failed, skipping\n",
+								noiselevel=-1)
+							continue
 						if not self._visible(db, cpv, metadata):
 							continue
 						matches.add(cpv)
@@ -197,8 +203,14 @@ class search(object):
 					for cpv in reversed(matches):
 						if portage.cpv_getkey(cpv) != cp:
 							continue
-						metadata = zip(db_keys,
-							db.aux_get(cpv, db_keys))
+						try:
+							metadata = zip(db_keys,
+								db.aux_get(cpv, db_keys))
+						except KeyError:
+							portage.writemsg("emerge: search: "
+								"aux_get() failed, skipping\n",
+								noiselevel=-1)
+							continue
 						if not self._visible(db, cpv, metadata):
 							continue
 						if not result or cpv == portage.best([cpv, result]):
-- 
2.0.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] search._xmatch: handle aux_get KeyError (525718)
  2014-12-11  7:51 [gentoo-portage-dev] [PATCH] search._xmatch: handle aux_get KeyError (525718) Zac Medico
@ 2014-12-11  8:08 ` Alexander Berntsen
  2014-12-11  8:33 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
  1 sibling, 0 replies; 4+ messages in thread
From: Alexander Berntsen @ 2014-12-11  8:08 UTC (permalink / raw
  To: gentoo-portage-dev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

I don't have a suggestion for where to put it, but I really dislike
having the exact same thing twice like this.

- -- 
Alexander
bernalex@gentoo.org
https://secure.plaimi.net/~alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iF4EAREIAAYFAlSJUPUACgkQRtClrXBQc7UnSgD+MwGTCNZNY41PMgakwD/3ASs2
gpknBhUet2oI5WteoKwA/jjj191j9VmxsaK7xD0Zv8uhs4MxdbYgJ7ydRKFKANL6
=6vpE
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [gentoo-portage-dev] [PATCH v2] search._xmatch: handle aux_get KeyError (525718)
  2014-12-11  7:51 [gentoo-portage-dev] [PATCH] search._xmatch: handle aux_get KeyError (525718) Zac Medico
  2014-12-11  8:08 ` Alexander Berntsen
@ 2014-12-11  8:33 ` Zac Medico
  2014-12-11  8:36   ` Alexander Berntsen
  1 sibling, 1 reply; 4+ messages in thread
From: Zac Medico @ 2014-12-11  8:33 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

Since commit 55c8c8bc7a781e3f71ce92922eea64ad4cafce3c, emerge --search
can raise an unhandled KeyError if a pkg_desc_index contains a stale
package. Handle it with the same error message used for other aux_get
failures.

Fixes: 55c8c8bc7a78 ("Add emerge --search-index option.")
X-Gentoo-Bug: 525718
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=525718
---
PATCH v2 splits out a _aux_get_error method to unify the error output
formatting.

 pym/_emerge/search.py | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/pym/_emerge/search.py b/pym/_emerge/search.py
index 90dbcec..e7f6f44 100644
--- a/pym/_emerge/search.py
+++ b/pym/_emerge/search.py
@@ -1,6 +1,8 @@
 # Copyright 1999-2014 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 import re
 import portage
 from portage import os
@@ -86,6 +88,11 @@ class search(object):
 				pass
 		raise KeyError(args[0])
 
+	def _aux_get_error(self, cpv):
+		portage.writemsg("emerge: search: "
+			"aux_get('%s') failed, skipping\n" % cpv,
+			noiselevel=-1)
+
 	def _findname(self, *args, **kwargs):
 		for db in self._dbs:
 			if db is not self._portdb:
@@ -166,8 +173,12 @@ class search(object):
 				else:
 					db_keys = list(db._aux_cache_keys)
 					for cpv in db.match(atom):
-						metadata = zip(db_keys,
-							db.aux_get(cpv, db_keys))
+						try:
+							metadata = zip(db_keys,
+								db.aux_get(cpv, db_keys))
+						except KeyError:
+							self._aux_get_error(cpv)
+							continue
 						if not self._visible(db, cpv, metadata):
 							continue
 						matches.add(cpv)
@@ -197,8 +208,12 @@ class search(object):
 					for cpv in reversed(matches):
 						if portage.cpv_getkey(cpv) != cp:
 							continue
-						metadata = zip(db_keys,
-							db.aux_get(cpv, db_keys))
+						try:
+							metadata = zip(db_keys,
+								db.aux_get(cpv, db_keys))
+						except KeyError:
+							self._aux_get_error(cpv)
+							continue
 						if not self._visible(db, cpv, metadata):
 							continue
 						if not result or cpv == portage.best([cpv, result]):
@@ -257,9 +272,7 @@ class search(object):
 					full_desc = self._aux_get(
 						full_package, ["DESCRIPTION"])[0]
 				except KeyError:
-					portage.writemsg(
-						"emerge: search: aux_get() failed, skipping\n",
-						noiselevel=-1)
+					self._aux_get_error(full_package)
 					continue
 				if not self.searchre.search(full_desc):
 					continue
@@ -337,7 +350,7 @@ class search(object):
 						metadata = dict(zip(metadata_keys,
 							self._aux_get(full_package, metadata_keys)))
 					except KeyError:
-						msg.append("emerge: search: aux_get() failed, skipping\n")
+						self._aux_get_error(full_package)
 						continue
 
 					desc = metadata["DESCRIPTION"]
-- 
2.0.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [gentoo-portage-dev] [PATCH v2] search._xmatch: handle aux_get KeyError (525718)
  2014-12-11  8:33 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
@ 2014-12-11  8:36   ` Alexander Berntsen
  0 siblings, 0 replies; 4+ messages in thread
From: Alexander Berntsen @ 2014-12-11  8:36 UTC (permalink / raw
  To: gentoo-portage-dev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Yeah this is nicer, go ahead & merge.
- -- 
Alexander
bernalex@gentoo.org
https://secure.plaimi.net/~alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iF4EAREIAAYFAlSJV4IACgkQRtClrXBQc7W+VgD7BUuZb940KY5hiQZUsEaLLLAD
PGDZKd2yIVtJB0uLJqAA/3/AQmjfht8+TAPmwWImiaykO3+oSCZXYARJfsnEv47X
=LMHO
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-12-11  8:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-11  7:51 [gentoo-portage-dev] [PATCH] search._xmatch: handle aux_get KeyError (525718) Zac Medico
2014-12-11  8:08 ` Alexander Berntsen
2014-12-11  8:33 ` [gentoo-portage-dev] [PATCH v2] " Zac Medico
2014-12-11  8:36   ` Alexander Berntsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox