exoscale / cs

A simple, yet powerful CloudStack API client for python and the command-line.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add more verbosity to CloudStack exception error messages

synergiator opened this issue · comments

commented

Currently, errors do not include details. In an exception log you would read something of the sort:

cs.client.CloudStackApiException: HTTP 530 response from CloudStack

While if same error caused during a CloudMonkey call, you would find additionally the error code and message:

Error: (HTTP 530, error code 4250) Internal error executing command, please contact your system administrator

UPDATE. After a closer look, it seems that there might be a bug or not used feature in cs - a flag to use json as it seems - regarding JSON parsing of the Response.

Currently, response.json() could provide for example the following data if there is an error:

.{'listtemplatesresponse': {'cserrorcode': 9999,
                           'errorcode': 431,
                           'errortext': 'Unable to execute API command '
                                        'listtemplates due to missing '
                                        'parameter templatefilter',
                           'uuidList': []}}

In a test hack I've tried to change original code of [cs/client.py](https://github.com/exoscale/cs/blob/e8784588b3040750119f68eef5cd1ba3b602b4d2/cs/client.py#L352):

        if response.status_code != 200:
            raise CloudStackApiException(
                "HTTP {0} response from CloudStack".format(
                    response.status_code),
                error=data,
                response=response)

as the following:

        if response.status_code != 200:
                ddata = response.json()
                k,val = ddata.popitem()
                errmsg="HTTP %s response from CloudStack.\ncserrorcode %s: %s" % (response.status_code, val['cserrorcode'], val['errortext'])
             
             raise CloudStackApiException(
                 errmsg, 
                 error=data,
                 response=response)

This results in a more detailed output.

E           cs.client.CloudStackApiException: HTTP 431 response from CloudStack.
E           cserrorcode 9999: Unable to execute API command listtemplates due to missing parameter templatefilter

This hack does not follow the original logic though, because the method signature in this context containes the boolean function argument json, and the code in question is for the case "it's not json" as it seems.

For time being, ambigous error messages containing just HTTP error code are really a headache. Who knows what should be behind a 431 in terms which parameter exactly is missing, or which backend problem is a HTTP 530?

commented

solved with #117!