Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raise exceptions #78

Open
hartsock opened this issue Jul 17, 2014 · 5 comments
Open

raise exceptions #78

hartsock opened this issue Jul 17, 2014 · 5 comments

Comments

@hartsock
Copy link
Member

At present actions that seem like they would throw exceptions do not. Instead the error is transmitted as part of a data object and the programmer is expected to check for an exception before proceeding.

Example:

   for vm in vmList:
       if vm.name in vmnames:
           if vm.runtime.powerState != vim.VirtualMachinePowerState.poweredOn:
              task = vm.PowerOn()
              WaitForTasks([task], si)
           lease = vm.ExportVm()
           if lease.error:
                raise lease.error

... this is currently anticipated behavior, so most programmers who have been using the lib for a number of years will have code built to handle this kind of check. The problem is new programmers will expect the method to actually raise an exception (the method's documentation states that it raises exceptions when in pyVmomi it never does).

Enhancement

When an exception occurs on a remote method, raise the exception as if it occurred in Python. This is the most pythonic way to handle raising an exception.

@michaelrice
Copy link
Contributor

+1 on this.

@larsskj
Copy link

larsskj commented Apr 25, 2016

Yes - +1.

@lingfish
Copy link

Is this still not done?

@prziborowski
Copy link

I'm not sure how it would work for that example that you have.
ExportVm returns a lease. At that point in time, it isn't known if the lease has an error or not (it likely will be unset in your example and the lease.state will be initializing).

So are you suggesting that every time a remote method on a managed object is called it checks for an "error" property and raising an exception?

Export/Import VM/vApp seems to be quite an exceptional part of the VIM API as it is relying on an out-of-band method to download/upload files. It even lets you pass an exception to the server with abort(MethodFault).

@larsskj
Copy link

larsskj commented Apr 20, 2017

So are you suggesting that every time a remote method on a managed object is called it checks for an "error" property and raising an exception?

Exactly: That's the pythonese way to do it. As it is today, it's forcing Python developers into writing code in a very non-pythonese way. That's a serious usability degradation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants