ABSPOSUE ; IHS/FCS/DRS - impossible errors ;
;;1.0;PHARMACY POINT OF SALE;**17**;JUN 21, 2001;Build 38
Q
;----------------------------------------------------------------------
;IHS/SD/RLT - 04/10/06 - Patch 17
; Fixed <NOTOPEN> error with E1 lookup.
; Run HOME^%ZIS whether IOF is set or not.
;----------------------------------------------------------------------
;
; 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^ABSPOSUE(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
;IHS/SD/RLT - 04/10/06 - Patch 17 - begin
;D:'$D(IOF) HOME^%ZIS ; make sure screen vars there
D HOME^%ZIS ;RLT
;IHS/SD/RLT - 04/10/06 - Patch 17 - end
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
H $R(10)+1 ; could help various things (locks, database conditions)
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($T(+0),$J)=DUZ^$H last time we did this
N X S X=$G(^TMP($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($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:$Q 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^ABSPOSUE("P","TIR","Additional Message",.MYEXMSG,"point 1","MYROU")
W !,"returned value = ",X,!
Q
ABSPOSUE ; IHS/FCS/DRS - impossible errors ;
+1 ;;1.0;PHARMACY POINT OF SALE;**17**;JUN 21, 2001;Build 38
+2 QUIT
+3 ;----------------------------------------------------------------------
+4 ;IHS/SD/RLT - 04/10/06 - Patch 17
+5 ; Fixed <NOTOPEN> error with E1 lookup.
+6 ; Run HOME^%ZIS whether IOF is set or not.
+7 ;----------------------------------------------------------------------
+8 ;
+9 ; Deal with impossible errors (errors which should never occur,
+10 ; and which weren't already trapped by M).
+11 ;
IMPOSS(UETYPE,UEOPT,UEMSG,UEMSG2,UELOC,UEROU,UENOLOG) ;EP - deal with impossible errors - called from many places
+1 ; $$IMPOSS^ABSPOSUE(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 ;IHS/SD/RLT - 04/10/06 - Patch 17 - begin
+59 ;D:'$D(IOF) HOME^%ZIS ; make sure screen vars there
+60 ;RLT
DO HOME^%ZIS
+61 ;IHS/SD/RLT - 04/10/06 - Patch 17 - end
+62 USE IO
+63 IF '$DATA(IORVON)
NEW IORVON,IORVOFF
Begin DoDot:1
+64 NEW X
SET X="IORVON;IORVOFF"
DO ENDR^%ZISS
End DoDot:1
+65 WRITE !!,IORVON
+66 WRITE "An unexpected problem has been detected; notify programmer!"
+67 IF $DATA(UELOC)!$DATA(UEROU)
Begin DoDot:1
+68 WRITE !?5,"The problem occurred "
+69 IF $DATA(UELOC)
WRITE "at location ",UELOC," "
IF $X>60
WRITE !
+70 IF $DATA(UEROU)
WRITE "in routine ",UEROU
+71 WRITE ".",!
End DoDot:1
+72 WRITE !?5,"The likely source"
IF UETYPE[","
WRITE "s"
+73 WRITE " of such a problem "
WRITE $SELECT(UETYPE[",":"are",1:"is"),":",!!?5
+74 IF UETYPE["FM"
Begin DoDot:1
+75 WRITE "Fileman has reported an error to the program.",!?5
End DoDot:1
+76 IF UETYPE["L"
Begin DoDot:1
+77 WRITE "An interlock could not be obtained.",!?5
End DoDot:1
+78 IF UETYPE["DB"
Begin DoDot:1
+79 WRITE "An inconsistency in the database was detected.",!?5
End DoDot:1
+80 IF UETYPE["DEV"
Begin DoDot:1
+81 WRITE "An error condition trying to open a device or a file.",!?5
End DoDot:1
+82 IF UETYPE["P"
Begin DoDot:1
+83 WRITE "A condition the program was unprepared to handle",!?5
+84 WRITE "or perhaps an error in the program logic.",!?5
End DoDot:1
+85 WRITE !,"A programmer should be notified of this unfortunate event.",!
+86 DO MSG(.UEMSG)
DO MSG(.UEMSG2)
+87 WRITE IORVOFF,!!
+88 ;
+89 ; 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 ; could help various things (locks, database conditions)
HANG $RANDOM(10)+1
+4 IF $QUIT
QUIT $SELECT(UECHOICE="I":0,UECHOICE="R":1)
QUIT
+5 ;
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($T(+0),$J)=DUZ^$H last time we did this
+2 NEW X
SET X=$GET(^TMP($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($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
IF $QUIT
QUIT
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^ABSPOSUE("P","TIR","Additional Message",.MYEXMSG,"point 1","MYROU")
+3 WRITE !,"returned value = ",X,!
+4 QUIT