vmware / vsphere-automation-sdk-python

Python samples, language bindings, and API reference documentation for vSphere, VMC, and NSX-T using the VMware REST API
MIT License
747 stars 313 forks source link

Exceptions do not have error messages or error type when converting to string #280

Open lvalerio opened 3 years ago

lvalerio commented 3 years ago

Environment

Steps or code snippet to reproduce

Generate any exception with the VMC SDK. For example, deleting an SDDC that is in the process of being created, calling a get on an SDDC that does not exist, etc. When you try to convert the error to a string using the function str() the string you get back loses all information about the error.

Actual behavior

Calling delete on an SDDC that is in the process of being created returns an InvalidRequest which is correct but when we convert the error to a string we get {{messages : [], data : {{}}, error_type : None}}. The same thing happens with numerous other exceptions. However, we you call the to_json() function of the error, you get:

{"messages":[],"data":{"error_code":"skyscraper.sddc.not.ready.for.delete","error_messages":["Sddc is currently not in a state where it can be deleted. Please try once the status is READY or FAILED."],"retryable":false,"status":400,"path":"/vmc/api/orgs/REDACTED/sddcs/REDACTED"}}

Expected behavior

We should be returning an error message and the error type as strings something like {{messages : ['The sddc is not in a state that's valid for deletion'], data : {{}}, error_type : InvalidRequest }}. At the very least we should return the same string we get when we call the to_json() function of the error.

shwetapurohit commented 3 years ago

@lvalerio : I could reproduce the issue, It’s an issue in Python Runtime. I've filed a bug