Question
· Mar 5, 2019

Get locked register from error status

Hi all,

Lets imagine that there's a process that locks an entry of a gived domain, in my example the ID 2 of the table User.tApplications and using an exclusive lock.  Additionally the error handling is managed by a $ETrap routine wich will look for error data in order to log it


Set $ETrap = "Do Err1^ErrRoutine"

Set obj = ##class(User.tApplications).%OpenId(2,"4",.errors)

If ($System.Status.IsError(errors){
// Error: ERR_PESSIMISTIC_LOCK
   Set $ECode = <MyerrorCode>
}

When a  second process try to do the same action will cause an error informing that there's a lock (that is ok)

NS>d $System.Status.DecomposeStatus(error,.b)
 
NS>zw b
b=1
b(1)="ERROR #5803: Failed to acquire exclusive lock on instance of 'User.tApplications'"
b(1,"caller")="%LoadData+6^User.tApplications.1"
b(1,"code")=5803
b(1,"dcode")=5803
b(1,"domain")="%ObjectErrors"
b(1,"namespace")="ACB"
b(1,"param")=1
b(1,"param",1)="User.tApplications"
b(1,"stack")=$lb("e^%LoadData+6^User.tApplications.1^5","e^%Open+16^%Library.Persistent.1^1","e^%OpenId+1^%Library.Persistent.1^1","e^^^0")

As we can see on the decomposed status there's no information about which register is locked.

 

As the error is managed by a generic routine, the description of the error will be placed on the  `%objlasterror` object wich has the same information as the previous `b`  variable

Is there a way to get the register that caused  the fail to acquire exclusive lock from %objlasterror or any error variable?  We are trying to avoid pasing the register id as parameter to the error routine from every place that this error can be triggered

Thanks in advance

Discussion (1)1
Log in or sign up to continue

Hello,

I think, you should simply append your own error message like that : 

Set obj = ##class(User.tApplications).%OpenId(YourTApplicationId,"4",.errors)
Set:$$$ISERR(errors) errors = $$$ADDSC(errors,$$$ERROR($$$GeneralError,$$$FormatText("%OpenId failed for User.tApplications with id %1",YourTApplicationId)))

If an error occurs, variable "errors" will contain 2 errors.

NS>d $System.Status.DecomposeStatus(error,.b)
 
NS>zw b

Your error is in the subscript b(2).

Add  #include %occStatus if you are in a routine (for macro usage).

Regards.