From 1919ce80deeb034efc8d9e269177a0afff91b8c8 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Mar 05 2020 15:23:02 +0000 Subject: [PATCH 1/2] raise GenericError instead of TypeError in filterResults Fixes: https://pagure.io/koji/issue/1421 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index b8fa55b..ef8e1b6 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -12377,7 +12377,7 @@ class RootExports(object): def filterResults(self, methodName, *args, **kw): """Execute the XML-RPC method with the given name and filter the results based on the options specified in the keywork option "filterOpts". The method - must return a list of maps. Any other return type will result in a TypeError. + must return a list of maps. Any other return type will result in a GenericError. Currently supported options are: - offset: the number of elements to trim off the front of the list - limit: the maximum number of results to return @@ -12396,7 +12396,7 @@ class RootExports(object): Execute the XML-RPC method with the given name and filter the results based on the options specified in the keywork option "filterOpts". The method must return a list of maps. Any other return type will - result in a TypeError. + result in a GenericError. Args: offset: the number of elements to trim off the front of the list @@ -12422,7 +12422,7 @@ class RootExports(object): _count = 1 if not isinstance(results, list): - raise TypeError('%s() did not return a list' % methodName) + raise koji.GenericError('%s() did not return a list' % methodName) order = filterOpts.get('order') if order: From 1f391a7edc66e701816e31b5990ed94c67b181b1 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Mar 05 2020 15:27:32 +0000 Subject: [PATCH 2/2] raise GenericError on non-existing API call count, filterResults and countAndFilterResults now raises GenericError if unknown API call is made Fixes: https://pagure.io/koji/issue/1421 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index ef8e1b6..c1bf31d 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -12353,9 +12353,12 @@ class RootExports(object): """Execute the XML-RPC method with the given name and count the results. A method return value of None will return O, a return value of type "list", "tuple", or "dict" will return len(value), and a return value of any other type will return 1. An - invalid methodName will raise an AttributeError, and invalid arguments will raise a - TypeError.""" - result = getattr(self, methodName)(*args, **kw) + invalid methodName will raise GenericError.""" + try: + method = getattr(self, methodName) + except AttributeError: + raise koji.GenericError("method %s doesn't exist" % methodName) + result = method(*args, **kw) if result is None: return 0 elif isinstance(result, (list, tuple, dict)): @@ -12413,7 +12416,11 @@ class RootExports(object): """ filterOpts = kw.pop('filterOpts', {}) - results = getattr(self, methodName)(*args, **kw) + try: + method = getattr(self, methodName) + except AttributeError: + raise koji.GenericError("method %s doesn't exist" % methodName) + results = method(*args, **kw) if results is None: return 0, None elif isinstance(results, list):