#2027 raise GenericError instead of TypeError in filterResults
Merged 4 years ago by tkopecek. Opened 4 years ago by tkopecek.
tkopecek/koji issue1421  into  master

file modified
+14 -7
@@ -12353,9 +12353,12 @@ 

          """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)):
@@ -12377,7 +12380,7 @@ 

      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 +12399,7 @@ 

          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
@@ -12413,7 +12416,11 @@ 

          """

          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):
@@ -12422,7 +12429,7 @@ 

              _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:

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

4 years ago

We should really fix this where the error is raised in countAndFilterResults. That is also a call handler and also should not be deliberately raising exceptions that don't pass nicely to the client.

rebased onto 5a2fe1aad09fe11b17523b3a3653add9f5dd48f8

4 years ago

Metadata Update from @jcupova:
- Pull-request untagged with: testing-ready

4 years ago

pretty please pagure-ci rebuild

4 years ago

1 new commit added

  • raise GenericError on non-existing API call
4 years ago

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

4 years ago

rebased onto 1919ce8

4 years ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

4 years ago

Commit 2678617 fixes this pull-request

Pull-Request has been merged by tkopecek

4 years ago