• Re: How to capture ZLINK errors programatically?

    From Jens@21:1/5 to kdtop on Wed Aug 17 14:42:56 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From kdtop@21:1/5 to All on Wed Aug 17 14:22:31 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From K.S. Bhaskar@21:1/5 to Jens on Wed Aug 17 18:47:42 2022
    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:

    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

    $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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From kdtop@21:1/5 to K.S. Bhaskar on Thu Aug 18 05:35:51 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From kdtop@21:1/5 to All on Thu Aug 18 05:33:00 2022
    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 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From K.S. Bhaskar@21:1/5 to kdtop on Thu Aug 18 07:58:49 2022
    On Thursday, August 18, 2022 at 8:35:52 AM UTC-4, kdtop wrote:
    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

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From kdtop@21:1/5 to K.S. Bhaskar on Fri Aug 19 05:37:15 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Jens_Lidestr=C3=B6m?=@21:1/5 to All on Thu Nov 17 02:26:07 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From K.S. Bhaskar@21:1/5 to [email protected] on Thu Nov 17 09:09:49 2022
    On Thursday, November 17, 2022 at 5:26:08 AM UTC-5, [email protected] wrote:
    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

    When I use PIPE devices, I tend to use the stderr deviceparameter to capture stderr of the pipe. For example:

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

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

    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

    u $p c "c","e"



    Regards
    – Bhaskar

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)