Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: MAGUERR1

MAGUERR1.m

Go to the documentation of this file.
  1. MAGUERR1 ;WOIFO/SG - ERROR HANDLING UTILITIES ; 3/9/09 12:53pm
  1. ;;3.0;IMAGING;**93**;Dec 02, 2009;Build 163
  1. ;; Per VHA Directive 2004-038, this routine should not be modified.
  1. ;; +---------------------------------------------------------------+
  1. ;; | Property of the US Government. |
  1. ;; | No permission to copy or redistribute this software is given. |
  1. ;; | Use of unreleased versions of this software requires the user |
  1. ;; | to execute a written test agreement with the VistA Imaging |
  1. ;; | Development Office of the Department of Veterans Affairs, |
  1. ;; | telephone (301) 734-0100. |
  1. ;; | |
  1. ;; | The Food and Drug Administration classifies this software as |
  1. ;; | a medical device. As such, it may not be changed in any way. |
  1. ;; | Modifications to this software may result in an adulterated |
  1. ;; | medical device under 21CFR820, the use of which is considered |
  1. ;; | to be a violation of US Federal Statutes. |
  1. ;; +---------------------------------------------------------------+
  1. ;;
  1. Q
  1. ;
  1. ;***** PRINTS THE DUMP OF THE ERROR STORAGE
  1. DUMP() ;
  1. Q:$D(^TMP("MAG-ERRROR-STORAGE",$J))<10
  1. N EPTR,I,NODE,TMP
  1. S NODE=$NA(^TMP("MAG-ERRROR-STORAGE",$J))
  1. ;=== Print the header
  1. D DUMPL("Code Message Text",1)
  1. D DUMPL(" Additional info")
  1. ;=== Print the errors
  1. S EPTR=""
  1. F S EPTR=$O(@NODE@(EPTR)) Q:EPTR="" D
  1. . ;--- Print the error descriptor
  1. . S TMP=@NODE@(EPTR,0)
  1. . D DUMPL($J(+TMP,4)_" "_$P(TMP,U,2),1)
  1. . S TMP=$P(TMP,U,3)
  1. . D:TMP'="" DUMPL(" Location: "_TMP)
  1. . ;--- Print the optional text
  1. . S I=""
  1. . F S I=$O(@NODE@(EPTR,1,I)) Q:I="" D
  1. . . D DUMPL(" "_@NODE@(EPTR,1,I))
  1. . . Q
  1. . Q
  1. ;===
  1. Q
  1. ;
  1. DUMPL(MSG,SKIP) ;
  1. I '$D(XPDNM) W:$G(SKIP) ! W MSG,! Q
  1. I $G(SKIP) D BMES^XPDUTL(MSG) Q
  1. D MES^XPDUTL(MSG)
  1. Q
  1. ;
  1. ;##### RETURNS A LIST OF ERROR CODES FROM THE ERROR STORAGE
  1. ;
  1. ; [ENCLOSE] Enclose the list in commas.
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; "" No errors
  1. ; ... List of error codes (in reverse chronological
  1. ; order) separated by commas.
  1. ;
  1. ERRLST(ENCLOSE) ;
  1. N I,LST
  1. S I=" ",LST=""
  1. F S I=$O(^TMP("MAG-ERRROR-STORAGE",$J,I),-1) Q:I'>0 D
  1. . S LST=LST_","_$P(^TMP("MAG-ERRROR-STORAGE",$J,I,0),U)
  1. . Q
  1. Q $S(LST="":"",$G(ENCLOSE):LST_",",1:$P(LST,",",2,9999))
  1. ;
  1. ;##### RETURNS DESCRIPTOR OF THE FIRST ERROR FROM THE ERROR STORAGE
  1. ;
  1. ; [.INFO] Reference to a local array where additional text
  1. ; associated with the error message is returned to
  1. ; (first level nodes; no 0-nodes). If there is no
  1. ; such text, this parameter will be undefined after
  1. ; the call.
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; <0 Error descriptor (see the $$ERROR^MAGUERR)
  1. ; "" Error storage is empty or it has not been
  1. ; enabled (see the CLEAR^MAGUERR)
  1. ;
  1. FIRSTERR(INFO) ;
  1. N I K INFO
  1. S I=$O(^TMP("MAG-ERRROR-STORAGE",$J,0)) Q:I'>0 ""
  1. M INFO=^TMP("MAG-ERRROR-STORAGE",$J,I,1)
  1. Q $G(^TMP("MAG-ERRROR-STORAGE",$J,I,0))
  1. ;
  1. ;##### RETURNS DESCRIPTOR OF THE LAST ERROR FROM THE ERROR STORAGE
  1. ;
  1. ; [.INFO] Reference to a local array where additional text
  1. ; associated with the error message is returned to
  1. ; (first level nodes; no 0-nodes). If there is no
  1. ; such text, this parameter will be undefined after
  1. ; the call.
  1. ;
  1. ; Return Values
  1. ; =============
  1. ; <0 Error descriptor (see the $$ERROR^MAGUERR)
  1. ; "" Error storage is empty or it has not been
  1. ; enabled (see the CLEAR^MAGUERR)
  1. ;
  1. LASTERR(INFO) ;
  1. N I K INFO
  1. S I=$O(^TMP("MAG-ERRROR-STORAGE",$J," "),-1) Q:I'>0 ""
  1. M INFO=^TMP("MAG-ERRROR-STORAGE",$J,I,1)
  1. Q $G(^TMP("MAG-ERRROR-STORAGE",$J,I,0))
  1. ;
  1. ;##### RETURNS ERRORS FROM A REMOTE PROCEDURE
  1. ;
  1. ; .RESULTS Reference to the first parameter (RPC result) of the
  1. ; entry point that implements the remote procedure.
  1. ;
  1. ; If the type of the remote procedure result is GLOBAL
  1. ; ARRAY or GLOBAL INSTANCE and the RESULTS stores a
  1. ; valid name of a node in the ^TMP global, then errors
  1. ; are returned "under" this node.
  1. ;
  1. ; Otherwise, the RPC result type is changed to ARRAY
  1. ; and errors are returned in the RESULTS array.
  1. ;
  1. ; [ERR] Error descriptor of the main problem (from the RPC's
  1. ; point of view ;-). Only the 2nd piece is used: the
  1. ; message is returned as the 2nd piece of the result
  1. ; descriptor (for compatibility with the old code).
  1. ; By default, a generic message is used.
  1. ;
  1. ; Return Values
  1. ; =============
  1. ;
  1. ; @MAG8RES@(0) Result descriptor
  1. ; ^01: 0
  1. ; ^02: Message (2nd piece of the ERR)
  1. ;
  1. ; @MAG8RES@(i) Error descriptor (see the $$ERROR^MAGUERR)
  1. ; ^01: Error code
  1. ; ^02: Message
  1. ; ^03: Error location
  1. ; ^04: Message type
  1. ;
  1. ; @MAG8RES@(j) Line of the additional info
  1. ; ^01: ""
  1. ; ^02: Text
  1. ;
  1. ; The MAG8RES value is either the value of the RESULTS parameter
  1. ; (global node) or the parameter's name ("RESULTS").
  1. ;
  1. ; Error descriptors are returned in reverse chronological order
  1. ; (most recent first).
  1. ;
  1. ; Notes
  1. ; =====
  1. ;
  1. ; In order to use this functionality, the error storage must be
  1. ; enabled and initialized in the beginning of the code that
  1. ; implements the remote procedure (see the CLEAR^MAGUERR). See the
  1. ; MAGGA0* routines for usage examples.
  1. ;
  1. RPCERRS(RESULTS,ERR) ;
  1. N CNT,EPTR,I,MAGLOBAL,MAG8RES,TMP
  1. ;=== Re-initialize the result array
  1. D:$G(RESULTS)?1"^TMP("1.E1")"
  1. . N $ESTACK,$ETRAP
  1. . S $ETRAP="S (MAG8RES,$ECODE)="""""
  1. . ;--- Check if the node name is valid
  1. . S MAG8RES=$NA(@RESULTS)
  1. . Q
  1. I $G(MAG8RES)="" D S MAG8RES="RESULTS"
  1. . ;--- Change type of the RPC result
  1. . S TMP=$$RTRNFMT^XWBLIB("ARRAY",1)
  1. . Q
  1. ;--- Clear the buffer
  1. K @MAG8RES
  1. ;
  1. ;=== Format the result descriptor (backward compatible)
  1. S TMP=$$TRIM^XLFSTR($P($G(ERR),U,2))
  1. S @MAG8RES@(0)="0"_U_$S(TMP'="":TMP,1:"RPC encountered error(s).")
  1. Q:$D(^TMP("MAG-ERRROR-STORAGE",$J))<10
  1. ;
  1. ;=== Get errors from the temporary storage
  1. S EPTR="",CNT=0
  1. F S EPTR=$O(^TMP("MAG-ERRROR-STORAGE",$J,EPTR),-1) Q:EPTR="" D
  1. . S TMP=$G(^TMP("MAG-ERRROR-STORAGE",$J,EPTR,0)) Q:'TMP
  1. . S CNT=CNT+1,@MAG8RES@(CNT)=TMP
  1. . S I=0
  1. . F S I=$O(^TMP("MAG-ERRROR-STORAGE",$J,EPTR,1,I)) Q:I'>0 D
  1. . . S CNT=CNT+1
  1. . . S $P(@MAG8RES@(CNT),U,2)=^TMP("MAG-ERRROR-STORAGE",$J,EPTR,1,I)
  1. . . Q
  1. . Q
  1. ;
  1. ;=== Cleanup
  1. D CLEAR^MAGUERR(0) ; Error storage
  1. K ^TMP("DILIST",$J) ; Default FileMan buffer
  1. Q
  1. ;
  1. ;+++++ DEFAULT RUN-TIME ERROR HANDLER
  1. ;
  1. ; MAGZZRCV Name of a variable that the error descriptor
  1. ; (-20) is assigned to.
  1. ;
  1. RTEHNDLR(MAGZZRCV) ;
  1. N MAGZZERR,MAGZZRC
  1. ;--- Record the error
  1. S MAGZZERR=$$EC^%ZOSV D ^%ZTER S $ECODE=""
  1. S MAGZZRC=$$ERROR^MAGUERR(-20,,MAGZZERR)
  1. ;--- Unwind the stack and assign/return the error descriptor
  1. S $ETRAP="S:$ESTACK'>0 $ECODE="""""
  1. S:MAGZZRCV'="" $ETRAP=$ETRAP_","_MAGZZRCV_"="_$$DDQ^MAGUTL05(MAGZZRC)
  1. S $ETRAP=$ETRAP_" Q:$QUIT "_$$DDQ^MAGUTL05(MAGZZRC)_" Q"
  1. S $ECODE=",U1,"
  1. Q:$QUIT MAGZZRC Q