From 5925781b9ad9a5ce9200ffcf67f3255bc5f8d0f7 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 24 Oct 2018 17:33:05 +0300 Subject: [PATCH] Proper message for APIError 0 --- src/api.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/api.py b/src/api.py index fd14b2fb..df364a17 100644 --- a/src/api.py +++ b/src/api.py @@ -1188,9 +1188,27 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler, object): try: # pylint: disable=attribute-defined-outside-init self._method = method - return self._handlers[method](self, *params) + func = self._handlers[method] + return func(self, *params) except KeyError: raise APIError(20, 'Invalid method: %s' % method) + except TypeError as e: + msg = "Unexpected internal error: %s" % e + if 'argument' not in str(e): + raise APIError(0, msg) + argcount = len(params) + maxcount = func.func_code.co_argcount + if argcount > maxcount: + msg = ( + "Command %s takes at most %s parameters (%s given)" % + (method, maxcount, argcount)) + else: + mincount = maxcount - len(func.func_defaults or []) + if argcount < mincount: + msg = ( + "Command %s takes at least %s parameters (%s given)" % + (method, mincount, argcount)) + raise APIError(0, msg) finally: state.last_api_response = time.time()