Stop Script after Syntax Error.

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
 
May 20, 2008
3,515
4
Elkridge, MD, USA
---- Original Message ----
From: krischik
To: ESFabian@zenge.org
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
 

rconn

Administrator
Staff member
May 14, 2008
12,344
149
> 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
Thread starter Title Forum Replies Date
vefatica Stop TPIPE /EOL removing bad EOLs (and TPIPE changine EOLs)? Support 2
vefatica Start/stop screensaver from TCC? Support 12
L WAD In console, tabs are rendered with non-uniform tab-stop spacing Support 16
T Fixed V18 debugger crashed on stop button Support 2
B How to? why does my BTM stop Support 2
F How to? Stop hijacking control-shift-z Support 6
A How to? Stop a command in the middle of its operation Support 10
Joe Caverly SCRIPT and GetObject Support 3
vefatica SCRIPT ... TCC disappears Support 2
T How can I send a simple parameter to a script, in tc 25? Support 2
vefatica PSHELL: How pass arguments to script? Support 15
EDerH Powershell call from script Support 24
Joe Caverly .PS1 script does not work with PSHELL Support 11
MickeyF running program from script and (not) returning to script Support 12
T Fixed Echo randomly activated in script Support 4
fpefpe How to? script error Support 1
fpefpe How to? script error Support 0
vefatica @SCRIPT bug persists Support 4
D Catching the result of an evaluated script expression Support 0
Joe Caverly Non-conforming @Script Support 6
M The Matrix: a useless script ... Support 5
fpefpe How to? LUA script Support 0
T Change language in script Support 4
Steve Pitts Documentation Script errors invoking help Support 15
R How to? Launch and execute commands in tcmd.exe through MSBuild Script. Support 3
Joe Caverly @SCRIPT does not like all comments Support 2
Mordachai Help! How to set parameters for script I'm debugging?! Support 6
fpefpe How to? Script support Support 8
JohnQSmith "SCRIPT" Support 7
rconn Script kiddies on the attack Support 4
H Ruby - Running External Ruby script crashes TCC Support 11
Joe Caverly SCRIPT Command Support 2
T Obfuscating passwords in script Support 14
Stefano Piccardi IDE.exe start toobar button fails when % in script path Support 0
lassevk exit(1) in a python script exits console, by design or bug? Support 1
R break script on syntex error Support 7
K iftp script copy deletes target files Support 17
R script problem with mapped network drive Support 1
M syntax for sftp with publickey Support 3
vefatica IDE external command syntax color? Support 1
Joe Caverly Command Input Syntax Colouring Support 3
C Nested IF syntax — TCC behaving differently to CMD Support 12
rps Documentation Regular expression syntax link broken Support 1
Dan Glynhampton Documentation v15 help: Syntax error in example of @DEC Support 0
D Syntax error when redirecting eval Support 5
C @diskfree[ ] syntax in 15.00.17 Support 0
T Syntax highlighting in the IDE Support 8
cgunhouse Eventlog Syntax issue Support 8
J syntax problems multiple commands (command & command) Support 4
C CMD's "nested quote" syntax Support 3

Similar threads