Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Stop Script after Syntax Error.

Feb
50
1
Hello,

I just trashed a few dozen files because TakeCommand would happily continue after an IFF statement with a syntax error. Damm.

Anyway, that brings me to the question: Is there an easy option which tells TakeCommand to stop execution of a script after an syntax error?

Up until know I used:

Code:
SETLOCAL
    ON BREAK                        GOTO Catch
    ON ERROR                        GOTO Catch
    ON CONDITION ERRORLEVEL NE 0    GOTO Catch

…

ENDLOCAL

QUIT 0

:Catch
    ON CONDITION
    ON BREAK
    ON ERROR

    ECHO External Error: %[_?]:      %@ErrText[%_?]
    ECHO System   Error: %[_SYSERR]: %@ErrText[%_SYSERR]
ENDLOCAL
CANCEL 1

This will end execution on most errors but leaves you without a useful error message and is a mouthful of code to type in. And this time I forgot to copy paste it.

Martin
 
Just found this discussion. And I am with roytam1 here. Syntax errors on control structures (IF, IFF, FOR, DO) are extremely dangerous.

For example, spot the bug and consider what happened:

Code:
        DO Card_File IN /S /A:-D /[!.svn .backups] *
            SET Home_File=%[USERPROFILE]\%@Right[%[Card_Dir_Len], %@Full[%[Card_File]]]
            IFF NOT EXITS "%[Home_File]" THEN
                IFF NOT EXITS "%@Path[%[Home_File]]" THEN
                    MKDIR /S "%@Path[%[Home_File]]"
                ENDIFF

                COPY "%[Card_File]" "%[Home_File]"
            ELSEIFF %@Compare["%[Card_File]","%[Home_File]"] == 0 THEN
                gvimdiff "%[Card_File]" "%[Home_File]"
            ENDIFF
        ENDDO

Did not find it?

Hint 1: It´s in the IFF — the DO is just there to show the whole magnitude of disaster.
Hint 2: Am an not a native English speaker and dyslexic: its a spelling mistake by which to letters are reversed.

I am with CMD here in treating syntax errors in control structures differently and aborting immediately.

Martin
 
---- Original Message ----
From: krischik
To: [email protected]
Sent: Monday, 2011. November 21. 07:43
Subject: RE: [Support-t-3382] Re: Stop Script after Syntax Error.

| Just found this discussion. And I am with roytam1 here. Syntax errors
| on control structures (IF, IFF, FOR, DO) are extremely dangerous.
|
| For example, spot the bug and consider what happened:
|
|
| Code:
| DO Card_File IN /S /A:-D /[!.svn .backups] *
| SET Home_File=%[USERPROFILE]\%@Right[%[Card_Dir_Len],
| %@Full[%[Card_File]]]
| IFF NOT EXITS "%[Home_File]" THEN
| IFF NOT EXITS "%@Path[%[Home_File]]" THEN
| MKDIR /S "%@Path[%[Home_File]]"
| ENDIFF
|
| COPY "%[Card_File]" "%[Home_File]"
| ELSEIFF %@Compare["%[Card_File]","%[Home_File]"] == 0 THEN
| gvimdiff "%[Card_File]" "%[Home_File]"
| ENDIFF
| ENDDODid not find it?
|
| Hint 1: It´s in the IFF — the DO is just there to show the whole
| magnitude of disaster.
| Hint 2: Am an not a native English speaker and dyslexic: its a
| spelling mistake by which to letters are reversed.
|
| I am with CMD here in treating syntax errors in control structures
| differently and aborting immediately.

I agree with you on the treatment of errors. Regardless, to assist you to avoid this particular issue, I have the following suggestions:

1/ Instead of the status test "EXIST" use "ISDIR" or "ISFILE", as appropriate. Likelihood of a false matches is reduced.

2/ ANY alias or batch file which makes wholesale changes should be thoroughly testsd using the /N option (report what the command WOULD do, but don't actually do it) available in the COPY, DEL, REN, etc. commands.
--
Steve
 
> I am with CMD here in treating syntax errors in control structures
> differently and aborting immediately.

If you can point me to any mention of this behavior in Microsoft's
documentation for CMD, I will consider making it the default (probably only
for TCC/LE, as it will break the batch debugger).

Otherwise, I'll continue to treat it as a CMD bug.
 
If you can point me to any mention of this behavior in Microsoft's documentation for CMD, I will consider making it the default
How about just making it optional, with an indication against the option that either it breaks the debugger, or perhaps better that it will be ignored when the debugger is running??
 

Similar threads

Back
Top