PowerCLIGoodies / DRSRule

PowerShell module with support for managing vSphere DRS Rules and Groups
29 stars 9 forks source link

Errors not throwing actual error. #8

Closed nwsparks closed 6 years ago

nwsparks commented 7 years ago

The functions are throwing custom errors rather than passing the original error back out which is problematic. I ran into an issue when trying to wrap your module into another function where the drsrule functions were failing because I wasn't importing the vmware module into the global scope. So rather than the error displaying what was really happening (get-vm command not found) it was saying the vm itself wasn't found which was not the issue at all.

I changed the below with a possible alternative

          try {
            ## limit scope to this cluster
            $oThisCluster | Get-VM -Name $oThisVmItem -ErrorAction:Stop
          }
          catch {
          #this commented out is the original message
          #Throw "No VM of name '$oThisVmItem' found in cluster '$($oThisCluster.Name)'. Valid VM name?"
          Throw "$($oThisCluster.Name) - Error looking up $oThisVmItem - $($_.Exception.Message)"
          }
mtboren commented 7 years ago

Greets, @nwsparks --

Ah, yes, I can see how that is problematic. I will look into enhancing the module such it returns info about the "real" error that happens, not some assumption about what happened. Thanks for the sample snippet, too.