BPSOSUE ;BHAM ISC/FCS/DRS/FLS - impossible errors ;03/07/08 10:42
;;1.0;E CLAIMS MGMT ENGINE;**1,7**;JUN 2004;Build 46
;;Per VHA Directive 2004-038, this routine should not be modified.
;
; Deal with impossible errors (errors which should never occur,
; and which weren't already trapped by M).
;
IMPOSS(UETYPE,UEOPT,UEMSG,UEMSG2,UELOC,UEROU,UENOLOG) ;EP - deal with impossible errors - called from many places
; $$IMPOSS^BPSOSUE(UETYPE,UEOPT,UEMSG,UELOC,UEROU)
; UETYPE = kinds of problems which may have occured
; ["FM" a Fileman call has returned an error
; ["L" a LOCK with ample time has failed
; ["DB" a database error (some missing/incorrect field)
; ["P" a programming error / some unexpected condition
; ["DEV" some kind of device or file error
; UEOPT = options available; first one listed is the default
; Defaults to "TRI"
; ["R" retry - retry the operation; log err
; ["I" ignore - continue as though operation had succeeded; log err
; ["T" abort - log err and terminate
; UEMSG = optionally, an additional message to output
; can be .MSG, and we'll walk the array for you.
; UEMSG2 = even more message, like UEMSG. In a Fileman call failure,
; you'd probably send .FDA,.MSG
; UELOC = location, any number or name unique to the calling routine
; UEROU = the name of the calling routine
; UENOLOG = true if you do not want error log entry to be made
;
; $$ returns 1 to retry, 0 to ignore
;
; Caller may do with these values what he desires.
;
; To prevent excessive errors, we won't actually log an error if
; another one has been logged recently.
;
; This routine really isn't as important as it looks. In fact,
; it will almost never be encountered in practice. Its existence
; owes mostly to an outrageous ruling made in the name of,
; but contrary to, the very quality and maintainability that forced
; errors give you. This in turn led to a significant delay
; in the release of a product which has been proven to be dependable
; in practice.
;
; Formerly, a zero/zero forced error was found at various places
; in the code. In 13 months at ANMC, 11 months at Sitka,
; and several months at Pawhuska, Wewoka, Santa Fe, and Taos, the
; zero div by zero traps were never encountered, but over $3,000,000
; in revenues were collected. The ironic thing is,
; without those extra checking, of things like Fileman return values,
; sanity checks on input values, etc., the product would have been
; less reliable, yet it would have sailed through the verifiction
; phase of the project plan.
;
; Forced errors already pervade all of the M language. <UNDEF> is
; a forced error, for example. And forced errors are an integral part
; of the design of the very hardware that runs these programs.
; Follow the anti-forced error policy to its logical end and you
; go to Intersleaze and say "stop issuing <UNDEF> and instead,
; prompt the user for the opportunity to continue" and then you go
; to Intel and say "remove the addressing exception trap from your
; microcode; our support organization wouldn't be able to cope with
; the problem report on something like that."
;
I $G(UEOPT)="" S UEOPT="TRI"
I $G(ZTQUEUED) S UECHOICE=$E(UEOPT) G QD
D:'$D(IOF) HOME^%ZIS ; make sure screen vars there
U IO
I '$D(IORVON) N IORVON,IORVOFF D
. N X S X="IORVON;IORVOFF" D ENDR^%ZISS
W !!,IORVON
W "An unexpected problem has been detected; notify programmer!"
I $D(UELOC)!$D(UEROU) D
. W !?5,"The problem occurred "
. I $D(UELOC) W "at location ",UELOC," " W:$X>60 !
. I $D(UEROU) W "in routine ",UEROU
. W ".",!
W !?5,"The likely source" W:UETYPE["," "s"
W " of such a problem " W $S(UETYPE[",":"are",1:"is"),":",!!?5
I UETYPE["FM" D
. W "Fileman has reported an error to the program.",!?5
I UETYPE["L" D
. W "An interlock could not be obtained.",!?5
I UETYPE["DB" D
. W "An inconsistency in the database was detected.",!?5
I UETYPE["DEV" D
. W "An error condition trying to open a device or a file.",!?5
I UETYPE["P" D
. W "A condition the program was unprepared to handle",!?5
. W "or perhaps an error in the program logic.",!?5
W !,"A programmer should be notified of this unfortunate event.",!
D MSG(.UEMSG),MSG(.UEMSG2)
W IORVOFF,!!
;
N UECHOICE S UECHOICE=$$CHOICE ; Present the options; get I, R, T
QD ;
D LOGERR ; always log an error (unless too soon after prev. error)
I UECHOICE="T" G HALT
;LJE;H $R(10)+1 ; could help various things (locks, database conditions)
H 2
Q:$Q $S(UECHOICE="I":0,UECHOICE="R":1) Q
;
MSG(X) ; display message, directly or in array
I '$D(X) W "X is undefined",! Q
I $D(X)#10 W X,!
I $D(X)>9 D
. N R S R="X" F S R=$Q(@R) Q:R="" W @R,!
W !
Q
;
CHOICE() ; given UEOPT[letters, UETYPE too
I UEOPT="" S UEOPT="T"
N DIR,X,Y
I $L(UEOPT)=1 S X=UEOPT G CH5
S DIR(0)="SM^",X=""
I UEOPT["I" S X=X_"I:Ignore the problem and try to continue"
I UEOPT["R" S:X]"" X=X_";" S X=X_"R:Retry the operation"
I UEOPT["T" S:X]"" X=X_";" S X=X_"T:Terminate the program"
I UETYPE'="L" S X=X_" (WE RECOMMEND ""T"")"
S DIR(0)=DIR(0)_X
S DIR("B")=$E(UEOPT) D ^DIR
CH5 Q $S(X?1U:X,1:"T")
;
LOGERR ; log an error
; ^TMP($J,$T(+0),$J)=DUZ^$H last time we did this
N X S X=$G(^TMP($J,$T(+0),$J))
I $P(X,U)'=DUZ G LOG2
S X=$P(X,U,2) I +$H'=+X G LOG2
S X=$P(X,",",2) I $P($H,",",2)-X>300 G LOG2
I '$G(ZTQUEUED) D
. W !,"No additional error log entry will be made at this time.",!
Q
LOG2 ;
Q:$G(UENOLOG) ; requested: no error log entry
I '$G(ZTQUEUED) D
. W !,"Now recording some error log information to help the programmer...",!
D @^%ZOSF("ERRTN") ; trap an error
S ^TMP($J,$T(+0),$J)=DUZ_U_$H
I '$D(ZTQUEUED) D
. W ?10,"..." H 2 W "done.",!
Q
HALT ; halt
D H^XUS
; at this point, the user is logged off
; programmer shouldn't reach here, either, if HALT^ZU disinstackifies
Q "" ; <DPARM> error gets you back into programmer mode
TEST ;
N MYEXMSG,I F I=1:1:4 S MYEXMSG(I)="my extra msg line "_I
N X S X=$$IMPOSS^BPSOSUE("P","TIR","Additional Message",.MYEXMSG,"point 1","MYROU")
W !,"returned value = ",X,!
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HBPSOSUE 6258 printed Dec 13, 2024@01:52:18 Page 2
BPSOSUE ;BHAM ISC/FCS/DRS/FLS - impossible errors ;03/07/08 10:42
+1 ;;1.0;E CLAIMS MGMT ENGINE;**1,7**;JUN 2004;Build 46
+2 ;;Per VHA Directive 2004-038, this routine should not be modified.
+3 ;
+4 ; Deal with impossible errors (errors which should never occur,
+5 ; and which weren't already trapped by M).
+6 ;
IMPOSS(UETYPE,UEOPT,UEMSG,UEMSG2,UELOC,UEROU,UENOLOG) ;EP - deal with impossible errors - called from many places
+1 ; $$IMPOSS^BPSOSUE(UETYPE,UEOPT,UEMSG,UELOC,UEROU)
+2 ; UETYPE = kinds of problems which may have occured
+3 ; ["FM" a Fileman call has returned an error
+4 ; ["L" a LOCK with ample time has failed
+5 ; ["DB" a database error (some missing/incorrect field)
+6 ; ["P" a programming error / some unexpected condition
+7 ; ["DEV" some kind of device or file error
+8 ; UEOPT = options available; first one listed is the default
+9 ; Defaults to "TRI"
+10 ; ["R" retry - retry the operation; log err
+11 ; ["I" ignore - continue as though operation had succeeded; log err
+12 ; ["T" abort - log err and terminate
+13 ; UEMSG = optionally, an additional message to output
+14 ; can be .MSG, and we'll walk the array for you.
+15 ; UEMSG2 = even more message, like UEMSG. In a Fileman call failure,
+16 ; you'd probably send .FDA,.MSG
+17 ; UELOC = location, any number or name unique to the calling routine
+18 ; UEROU = the name of the calling routine
+19 ; UENOLOG = true if you do not want error log entry to be made
+20 ;
+21 ; $$ returns 1 to retry, 0 to ignore
+22 ;
+23 ; Caller may do with these values what he desires.
+24 ;
+25 ; To prevent excessive errors, we won't actually log an error if
+26 ; another one has been logged recently.
+27 ;
+28 ; This routine really isn't as important as it looks. In fact,
+29 ; it will almost never be encountered in practice. Its existence
+30 ; owes mostly to an outrageous ruling made in the name of,
+31 ; but contrary to, the very quality and maintainability that forced
+32 ; errors give you. This in turn led to a significant delay
+33 ; in the release of a product which has been proven to be dependable
+34 ; in practice.
+35 ;
+36 ; Formerly, a zero/zero forced error was found at various places
+37 ; in the code. In 13 months at ANMC, 11 months at Sitka,
+38 ; and several months at Pawhuska, Wewoka, Santa Fe, and Taos, the
+39 ; zero div by zero traps were never encountered, but over $3,000,000
+40 ; in revenues were collected. The ironic thing is,
+41 ; without those extra checking, of things like Fileman return values,
+42 ; sanity checks on input values, etc., the product would have been
+43 ; less reliable, yet it would have sailed through the verifiction
+44 ; phase of the project plan.
+45 ;
+46 ; Forced errors already pervade all of the M language. <UNDEF> is
+47 ; a forced error, for example. And forced errors are an integral part
+48 ; of the design of the very hardware that runs these programs.
+49 ; Follow the anti-forced error policy to its logical end and you
+50 ; go to Intersleaze and say "stop issuing <UNDEF> and instead,
+51 ; prompt the user for the opportunity to continue" and then you go
+52 ; to Intel and say "remove the addressing exception trap from your
+53 ; microcode; our support organization wouldn't be able to cope with
+54 ; the problem report on something like that."
+55 ;
+56 IF $GET(UEOPT)=""
SET UEOPT="TRI"
+57 IF $GET(ZTQUEUED)
SET UECHOICE=$EXTRACT(UEOPT)
GOTO QD
+58 ; make sure screen vars there
if '$DATA(IOF)
DO HOME^%ZIS
+59 USE IO
+60 IF '$DATA(IORVON)
NEW IORVON,IORVOFF
Begin DoDot:1
+61 NEW X
SET X="IORVON;IORVOFF"
DO ENDR^%ZISS
End DoDot:1
+62 WRITE !!,IORVON
+63 WRITE "An unexpected problem has been detected; notify programmer!"
+64 IF $DATA(UELOC)!$DATA(UEROU)
Begin DoDot:1
+65 WRITE !?5,"The problem occurred "
+66 IF $DATA(UELOC)
WRITE "at location ",UELOC," "
if $X>60
WRITE !
+67 IF $DATA(UEROU)
WRITE "in routine ",UEROU
+68 WRITE ".",!
End DoDot:1
+69 WRITE !?5,"The likely source"
if UETYPE[","
WRITE "s"
+70 WRITE " of such a problem "
WRITE $SELECT(UETYPE[",":"are",1:"is"),":",!!?5
+71 IF UETYPE["FM"
Begin DoDot:1
+72 WRITE "Fileman has reported an error to the program.",!?5
End DoDot:1
+73 IF UETYPE["L"
Begin DoDot:1
+74 WRITE "An interlock could not be obtained.",!?5
End DoDot:1
+75 IF UETYPE["DB"
Begin DoDot:1
+76 WRITE "An inconsistency in the database was detected.",!?5
End DoDot:1
+77 IF UETYPE["DEV"
Begin DoDot:1
+78 WRITE "An error condition trying to open a device or a file.",!?5
End DoDot:1
+79 IF UETYPE["P"
Begin DoDot:1
+80 WRITE "A condition the program was unprepared to handle",!?5
+81 WRITE "or perhaps an error in the program logic.",!?5
End DoDot:1
+82 WRITE !,"A programmer should be notified of this unfortunate event.",!
+83 DO MSG(.UEMSG)
DO MSG(.UEMSG2)
+84 WRITE IORVOFF,!!
+85 ;
+86 ; Present the options; get I, R, T
NEW UECHOICE
SET UECHOICE=$$CHOICE
QD ;
+1 ; always log an error (unless too soon after prev. error)
DO LOGERR
+2 IF UECHOICE="T"
GOTO HALT
+3 ;LJE;H $R(10)+1 ; could help various things (locks, database conditions)
+4 HANG 2
+5 if $QUIT
QUIT $SELECT(UECHOICE="I":0,UECHOICE="R":1)
QUIT
+6 ;
MSG(X) ; display message, directly or in array
+1 IF '$DATA(X)
WRITE "X is undefined",!
QUIT
+2 IF $DATA(X)#10
WRITE X,!
+3 IF $DATA(X)>9
Begin DoDot:1
+4 NEW R
SET R="X"
FOR
SET R=$QUERY(@R)
if R=""
QUIT
WRITE @R,!
End DoDot:1
+5 WRITE !
+6 QUIT
+7 ;
CHOICE() ; given UEOPT[letters, UETYPE too
+1 IF UEOPT=""
SET UEOPT="T"
+2 NEW DIR,X,Y
+3 IF $LENGTH(UEOPT)=1
SET X=UEOPT
GOTO CH5
+4 SET DIR(0)="SM^"
SET X=""
+5 IF UEOPT["I"
SET X=X_"I:Ignore the problem and try to continue"
+6 IF UEOPT["R"
if X]""
SET X=X_";"
SET X=X_"R:Retry the operation"
+7 IF UEOPT["T"
if X]""
SET X=X_";"
SET X=X_"T:Terminate the program"
+8 IF UETYPE'="L"
SET X=X_" (WE RECOMMEND ""T"")"
+9 SET DIR(0)=DIR(0)_X
+10 SET DIR("B")=$EXTRACT(UEOPT)
DO ^DIR
CH5 QUIT $SELECT(X?1U:X,1:"T")
+1 ;
LOGERR ; log an error
+1 ; ^TMP($J,$T(+0),$J)=DUZ^$H last time we did this
+2 NEW X
SET X=$GET(^TMP($JOB,$TEXT(+0),$JOB))
+3 IF $PIECE(X,U)'=DUZ
GOTO LOG2
+4 SET X=$PIECE(X,U,2)
IF +$HOROLOG'=+X
GOTO LOG2
+5 SET X=$PIECE(X,",",2)
IF $PIECE($HOROLOG,",",2)-X>300
GOTO LOG2
+6 IF '$GET(ZTQUEUED)
Begin DoDot:1
+7 WRITE !,"No additional error log entry will be made at this time.",!
End DoDot:1
+8 QUIT
LOG2 ;
+1 ; requested: no error log entry
if $GET(UENOLOG)
QUIT
+2 IF '$GET(ZTQUEUED)
Begin DoDot:1
+3 WRITE !,"Now recording some error log information to help the programmer...",!
End DoDot:1
+4 ; trap an error
DO @^%ZOSF("ERRTN")
+5 SET ^TMP($JOB,$TEXT(+0),$JOB)=DUZ_U_$HOROLOG
+6 IF '$DATA(ZTQUEUED)
Begin DoDot:1
+7 WRITE ?10,"..."
HANG 2
WRITE "done.",!
End DoDot:1
+8 QUIT
HALT ; halt
+1 DO H^XUS
+2 ; at this point, the user is logged off
+3 ; programmer shouldn't reach here, either, if HALT^ZU disinstackifies
+4 ; <DPARM> error gets you back into programmer mode
QUIT ""
TEST ;
+1 NEW MYEXMSG,I
FOR I=1:1:4
SET MYEXMSG(I)="my extra msg line "_I
+2 NEW X
SET X=$$IMPOSS^BPSOSUE("P","TIR","Additional Message",.MYEXMSG,"point 1","MYROU")
+3 WRITE !,"returned value = ",X,!
+4 QUIT