vmware / vmware/pyvmomi

raise exceptions

Open
#78 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement wishlist
Dominant language
Python
Stars
2.3k
Forks
763
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ExportVm example and trace how a remote method currently returns an object containing error instead of raising it. Compare this behavior with the method documentation, which says exceptions are raised, and identify the remote-method paths that would need consistent handling. Done means remote exceptions are raised as Python exceptions without requiring callers to inspect the returned object.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.