API Error Functions

Handling of OpenVSP ErrorObj information is accomplished through this group of API functions.

ErrorMgrSingleton

ErrorMgrSingleton.GetErrorLastCallFlag()

Check if there was an error on the last call to the API

ErrorMgrSingleton.GetNumTotalErrors()

Count the total number of errors on the stack

ErrorMgrSingleton.PopLastError()

Pop (remove) and return the most recent error from the stack.

ErrorMgrSingleton.GetLastError()

Return the most recent error from the stack (does NOT pop error off the stack)

ErrorMgrSingleton.SilenceErrors()

Prevent errors from printing to stdout as they occur.

ErrorMgrSingleton.PrintOnErrors()

Cause errors to be printed to stdout as they occur.

ErrorMgrSingleton.getInstance()

Get the error manager.

class openvsp.ErrorMgrSingleton(*args, **kwargs)[source]

ErrorMgrSingleton is the queue that API errors are reported through. An API function that fails pushes an ErrorObj onto it and returns a default value rather than throwing, so a script that does not check anything keeps running. Reach it with ErrorMgrSingleton.getInstance(), then use GetNumTotalErrors and PopLastError to find out what went wrong.

property thisown

The membership flag

__repr__()

Return repr(self).

GetErrorLastCallFlag()[source]

Check if there was an error on the last call to the API

err_mgr = ErrorMgrSingleton.getInstance()

err_mgr.SilenceErrors()

#==== Bogus call to raise an error ====#
SetParmVal( "BogusParmID", 23.0 )

assert err_mgr.GetErrorLastCallFlag(), "GetErrorLastCallFlag missed the error"

err_mgr.PrintOnErrors()

while err_mgr.GetNumTotalErrors() > 0:
    err_mgr.PopLastError()
Return type:

boolean

Returns:

False if no error, true otherwise

GetNumTotalErrors()[source]

Count the total number of errors on the stack

err_mgr = ErrorMgrSingleton.getInstance()

err_mgr.SilenceErrors()

#==== Two bogus calls, so the count is something to check ====#
SetParmVal( "BogusParmID", 23.0 )
SetParmVal( "AnotherBogusParmID", 23.0 )

assert err_mgr.GetNumTotalErrors() == 2, "GetNumTotalErrors did not count both errors"

err_mgr.PrintOnErrors()

while err_mgr.GetNumTotalErrors() > 0:
    err_mgr.PopLastError()
Return type:

int

Returns:

Number of errors

PopLastError()[source]

Pop (remove) and return the most recent error from the stack. Note, errors are printed on occurrence by default.

err_mgr = ErrorMgrSingleton.getInstance()

err_mgr.SilenceErrors()

SetParmVal( "BogusParmID", 23.0 )

n0 = err_mgr.GetNumTotalErrors()

err = err_mgr.PopLastError()

#==== Pop takes the error off the queue ====#
assert err_mgr.GetNumTotalErrors() == n0 - 1, "PopLastError left the error on the queue"

assert err.GetErrorCode() == VSP_CANT_FIND_PARM, "PopLastError returned the wrong error"

err_mgr.PrintOnErrors()

while err_mgr.GetNumTotalErrors() > 0:
    err_mgr.PopLastError()
Return type:

ErrorObj

Returns:

Error object

GetLastError()[source]

Return the most recent error from the stack (does NOT pop error off the stack)

err_mgr = ErrorMgrSingleton.getInstance()

err_mgr.SilenceErrors()

SetParmVal( "BogusParmID", 23.0 )

n0 = err_mgr.GetNumTotalErrors()

err = err_mgr.GetLastError()

#==== Unlike PopLastError, the error stays on the queue ====#
assert err_mgr.GetNumTotalErrors() == n0, "GetLastError removed the error"

assert err.GetErrorCode() == VSP_CANT_FIND_PARM, "GetLastError returned the wrong error"

err_mgr.PrintOnErrors()

while err_mgr.GetNumTotalErrors() > 0:
    err_mgr.PopLastError()

See also: SilenceErrors, PrintOnErrors; :rtype: ErrorObj :return: Error object

PopErrorAndPrint(ErrorMgrSingleton self, FILE * stream) → bool[source]
SilenceErrors()[source]

Prevent errors from printing to stdout as they occur.

err_mgr = ErrorMgrSingleton.getInstance()

#==== Errors are printed as they happen unless silenced ====#
err_mgr.SilenceErrors()

SetParmVal( "BogusParmID", 23.0 )

#==== The error is still recorded, it is only the printing that stops ====#
assert err_mgr.GetNumTotalErrors() == 1, "SilenceErrors also stopped the error being recorded"

err_mgr.PrintOnErrors()

while err_mgr.GetNumTotalErrors() > 0:
    err_mgr.PopLastError()

See also: PrintOnErrors

PrintOnErrors()[source]

Cause errors to be printed to stdout as they occur.

err_mgr = ErrorMgrSingleton.getInstance()

err_mgr.SilenceErrors()

SetParmVal( "BogusParmID", 23.0 )

#==== Turn printing back on ====#
err_mgr.PrintOnErrors()

assert err_mgr.GetNumTotalErrors() == 1, "PrintOnErrors lost the recorded error"

while err_mgr.GetNumTotalErrors() > 0:
    err_mgr.PopLastError()

See also: SilenceErrors

AddError(ErrorMgrSingleton self, vsp: :ERROR_CODE code, string const & desc)[source]
NoError(ErrorMgrSingleton self)[source]
MessageCallback(ErrorMgrSingleton self, MessageBase const * _from, MessageData const & data)[source]
static getInstance()[source]

Get the error manager. There is one queue for the whole session, and this is how a script reaches it – every other call in this group is made on the object returned here.

err_mgr = ErrorMgrSingleton.getInstance()

assert err_mgr.GetNumTotalErrors() >= 0, "getInstance did not return a usable error manager"

See also: GetNumTotalErrors, PopLastError, GetErrorLastCallFlag :rtype: ErrorMgrSingleton :return: ErrorMgrSingleton The one error manager for this session

ErrorObj

ErrorObj.GetErrorCode()

Get the ERROR_CODE enum of the last raised error

ErrorObj.GetErrorString()

Get the error string of the last raised error

class openvsp.ErrorObj(*args)[source]

ErrorObj is defined by an error code enum and associated error string.

property thisown

The membership flag

__repr__()

Return repr(self).

GetErrorCode()[source]

Get the ERROR_CODE enum of the last raised error

err_mgr = ErrorMgrSingleton.getInstance()

#==== Silence the errors so the bogus call below does not print ====#
err_mgr.SilenceErrors()

#==== Bogus call to raise an error ====#
SetParmVal( "BogusParmID", 23.0 )

err_mgr.PrintOnErrors()

err = err_mgr.PopLastError()

assert err.GetErrorCode() == VSP_CANT_FIND_PARM, "GetErrorCode did not report the missing Parm"

#==== Leave the queue as it was found ====#
while err_mgr.GetNumTotalErrors() > 0:
    err_mgr.PopLastError()

See also: ERROR_CODE :rtype: int :return: ERROR_CODE error code enum

GetErrorString()[source]

Get the error string of the last raised error

err_mgr = ErrorMgrSingleton.getInstance()

err_mgr.SilenceErrors()

SetParmVal( "BogusParmID", 23.0 )

err_mgr.PrintOnErrors()

err = err_mgr.PopLastError()

assert len( err.GetErrorString() ) > 0, "GetErrorString returned nothing to report"

while err_mgr.GetNumTotalErrors() > 0:
    err_mgr.PopLastError()
Return type:

string

Returns:

Error string

property m_ErrorCode

m_ErrorCode : vsp::ERROR_CODE

property m_ErrorString

m_ErrorString : string

NoError(ErrorObj self)[source]