Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to capture ZLINK errors programatically?

168 views
Skip to first unread message

kdtop

unread,
Aug 17, 2022, 5:22:33 PM8/17/22
to
I have reviewed the ZLINK documentation here:

https://docs.yottadb.com/ProgrammersGuide/commands.html#zlink

I would like to ZLINK a routine at runtime, and be aware if the compilation and linking generated any errors.

For example, I created a routine named TEST2, with the following erroneous code:

CHKERR2
SET X=
QUIT

And then I made another routine, TEST, with the following code.

CHKERR
DO
. NEW $ETRAP
. SET $ETRAP="write ""Error Trapped: "",$ECODE,! set $ETRAP="""",$ECODE="""""
. ZLINK "TMGTEST2"
QUIT

CHKMATHERR
DO
. NEW $ETRAP
. SET $ETRAP="write ""Error Trapped: "",$ECODE,! set $ETRAP="""",$ECODE="""""
. WRITE 1/0
QUIT

When I run this code, I can trap a divide by 0 error, but not a ZLINK error

yottadb>ZL "TMGTEST"

yottadb>do CHKERR^TMGTEST
SET X=
^-----
At column 9, line 1006, source module /opt/worldvista/EHR/p/TMGTEST2.m
%YDB-E-EXPR, Expression expected but not found

yottadb>do CHKMATHERR^TMGTEST
Error Trapped: ,M9,Z150373210,

Question:
Is there a way to trap a zlink error (in this case, a "%YDB-E-EXPR, Expression expected but not found")?

Thanks

Kevin



Jens

unread,
Aug 17, 2022, 5:42:59 PM8/17/22
to
kdtop schrieb am Mittwoch, 17. August 2022 um 23:22:33 UTC+2:
> I have reviewed the ZLINK documentation here:
>
> https://docs.yottadb.com/ProgrammersGuide/commands.html#zlink
>
> I would like to ZLINK a routine at runtime, and be aware if the compilation and linking generated any errors.
>
> For example, I created a routine named TEST2, with the following erroneous code:
>
> CHKERR2
> SET X=
> QUIT
>
> And then I made another routine, TEST, with the following code.
>
> CHKERR
> DO
> . NEW $ETRAP
> . SET $ETRAP="write ""Error Trapped: "",$ECODE,! set $ETRAP="""",$ECODE="""""
> . ZLINK "TMGTEST2"
> QUIT
>
> CHKMATHERR
> DO
> . NEW $ETRAP
> . SET $ETRAP="write ""Error Trapped: "",$ECODE,! set $ETRAP="""",$ECODE="""""
> . WRITE 1/0
> QUIT
>

I don't know how to do it with ZLINK, but maybe my Workaround helps you:

TESTCOMPILE(FILE,RESULT) ;Compile FILE (no Object File created and return possible Errors in .RESULT
N IO,PIPE,I,LINE
S IO=$IO
S PIPE="PIPE"
KILL RESULT
O PIPE:(shell="/bin/bash":command="$gtm_dist/mumps -noobject "_FILE_" && echo '***READY'":readonly)::"PIPE"
U PIPE
S I=1000
F Q:$ZEOF R LINE Q:LINE="***READY" D
. I $E(LINE,1,12)=($C(9,9)_"At column ") S RESULT(I)=$P($P(LINE,"At column ",2),",",1)_";"_$P($P(LINE,"line ",2),",",1)_";"
. I $E(LINE,1,4)="%YDB"!($E(LINE,1,4)="%GTM") S:$G(RESULT(I))="" RESULT(I)=";;" S RESULT(I)=RESULT(I)_LINE,I=I+1
C PIPE
U IO
Q

Jens

K.S. Bhaskar

unread,
Aug 17, 2022, 9:47:43 PM8/17/22
to
$ZCSTATUS (https://docs.yottadb.com/ProgrammersGuide/isv.html#zcstatus) captures the result of a ZCOMPILE. I don't know whether it captures the result of a ZLINK and I can't check right now, but in case it does not, you can always do ZCOMPILE before doing the ZLINK (which in any case only recompiles if necessary).

Regards
– Bhaskar

kdtop

unread,
Aug 18, 2022, 8:33:02 AM8/18/22
to
On Wednesday, August 17, 2022 at 5:42:59 PM UTC-4, Jens wrote:

Jens,

Thanks for taking the time to put all this together. I appreciated it!

Kevin

kdtop

unread,
Aug 18, 2022, 8:35:52 AM8/18/22
to
On Wednesday, August 17, 2022 at 9:47:43 PM UTC-4, K.S. Bhaskar wrote:
> On Wednesday, August 17, 2022 at 5:42:59 PM UTC-4, Jens wrote:
> > kdtop schrieb am Mittwoch, 17. August 2022 um 23:22:33 UTC+2:
> > > I have reviewed the ZLINK documentation here:
> > >
...
> $ZCSTATUS (https://docs.yottadb.com/ProgrammersGuide/isv.html#zcstatus) captures the result of a ZCOMPILE. I don't know whether it captures the result of a ZLINK and I can't check right now, but in case it does not, you can always do ZCOMPILE before doing the ZLINK (which in any case only recompiles if necessary).
>
> Regards
> – Bhaskar


Bhaskar,

Thanks for this reply. I did some more digging in the documentation about $ZCSTATUS and ZCOMPILE, and it seems that $ZSTATUS also returns information. Actually more verbose info:

yottadb>zcompile "/opt/worldvista/EHR/p/TMGTEST2.m"
SET X=
^-----
At column 9, line 1006, source module /opt/worldvista/EHR/p/TMGTEST2.m
%YDB-E-EXPR, Expression expected but not found

yottadb>W $ZSTATUS
150373210,CHKMATHERR+4^TMGTEST,%YDB-E-DIVZERO, Attempt to divide by zero
yottadb>W $ZCSTATUS
150372778
yottadb>


What keywords should I search for in the documentation to learn the meaning of the numbers for $ZCSTATUS? E.g. 150372778? There seems to be a difference between the numbers given for $ZSTATUS and $ZCSTATUS.

Thanks again
Kevin


K.S. Bhaskar

unread,
Aug 18, 2022, 10:58:50 AM8/18/22
to
Kevin –

$ZSTATUS (https://docs.yottadb.com/ProgrammersGuide/isv.html#zstatus) and $ZCSTATUS (https://docs.yottadb.com/ProgrammersGuide/isv.html#zcstatus) are different. You can SET the former, but the latter is read-only. https://docs.yottadb.com/MessageRecovery/errormsgref.html#zmessage-codes has a table of the error codes.

Regards
– Bhaskar

kdtop

unread,
Aug 19, 2022, 8:37:16 AM8/19/22
to
I tried to reproduce what I posted before and could not. Apparently the $ZSTATUS I posted was somehow left over from a prior execution. Here I show that $ZSTATUS is NOT set by ZLINK or ZCOMPILE.

This is consistent with what Bhaskar posted. Thanks for pointing me in the correct direction!

Kevin

yottadb>ZL "TMGTEST2"
SET X=
^-----
At column 9, line 574, source module /opt/worldvista/EHR/p/TMGTEST2.m
%YDB-E-EXPR, Expression expected but not found
%YDB-E-LABELMISSING, Label referenced but not defined: TRPCDone
%YDB-I-SRCNAM, in source module /opt/worldvista/EHR/p/TMGTEST2.m

yottadb>W $ZSTATUS

yottadb>W 1
1
yottadb>ZCOMPILE "/opt/worldvista/EHR/p/TMGTEST2.m"
SET X=
^-----
At column 9, line 574, source module /opt/worldvista/EHR/p/TMGTEST2.m
%YDB-E-EXPR, Expression expected but not found
%YDB-E-LABELMISSING, Label referenced but not defined: TRPCDone
%YDB-I-SRCNAM, in source module /opt/worldvista/EHR/p/TMGTEST2.m

yottadb>w $zstatus

yottadb>



On Thursday, August 18, 2022 at 10:58:50 AM UTC-4, K.S. Bhaskar wrote:
> > ...
> > > $ZCSTATUS (https://docs.yottadb.com/ProgrammersGuide/isv.html#zcstatus) captures the result of a ZCOMPILE. I don't know whether it captures the result of a ZLINK and I can't check right now, but in case it does not, you can always do ZCOMPILE before doing the ZLINK (which in any case only recompiles if necessary).
> > >
> > > Regards
> > > – Bhaskar
> > Bhaskar,
> >

> – Bhaskar

Jens Lideström

unread,
Nov 17, 2022, 5:26:08 AM11/17/22
to
In our application run commands from remote servers in a separate process with this command:

s output=call("mumps -run ^%XCMD 'w "Hello!",!'")

We read the output from the command with a PIPE device like this:

call(command)
n (command)
s ret=""
s p="myProcSystemCall"_$job
o p:(shell="/bin/sh":command=command:READONLY)::"PIPE" u p
f r line q:$zeof s ret=ret_$s($l(ret):$c(10),1:"")_line
c p
q ret

This seems to work fine for zlink also. Just change the command 'w "Hello!"' above to call zlink instead.

BR,
Jens Lideström

K.S. Bhaskar

unread,
Nov 17, 2022, 12:09:50 PM11/17/22
to
When I use PIPE devices, I tend to use the stderr deviceparameter to capture stderr of the pipe. For example:

YDB>o "c":(shell="/bin/sh":command="yottadb -noobject .yottadb/r/esvbug.m":stderr="e")::"pipe" u "c"

YDB>f r x q:$zeof u $p w x,! u "c"

YDB>u "e" f r x q:$zeof u $p w x,! u "e"
%YDB-E-FMLLSTMISSING, The formal list is absent from a label called with an actual list: lab2
%YDB-I-SRCNAM, in source module /home/bhaskar/.yottadb/r/esvbug.m

YDB>u $p c "c","e"

YDB>

Regards
– Bhaskar
0 new messages