mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-11 13:01:28 +02:00
30789: Add CONTINUE_ON_ERROR for old behaviour.
New behaviour is for scripts to exit on error instead of returning to top level and executing the next command.
This commit is contained in:
parent
1446625072
commit
7c56d77184
8 changed files with 95 additions and 17 deletions
|
@ -1,5 +1,11 @@
|
||||||
2012-11-15 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
2012-11-15 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||||
|
|
||||||
|
* 30789: Doc/Zsh/grammar.yo, Doc/Zsh/options.yo, Src/hist.c,
|
||||||
|
Src/init.c, Src/options.c, Src/zsh.h, Test/A04redirect.zsh: add
|
||||||
|
CONTINUE_ON_ERROR option for compatibility but turn it off:
|
||||||
|
scripts exit on an error instead of returning to the top-level
|
||||||
|
like interactive shells.
|
||||||
|
|
||||||
* 30800: Michal Halenka: Completion/Unix/Command/_arping: fix
|
* 30800: Michal Halenka: Completion/Unix/Command/_arping: fix
|
||||||
option.
|
option.
|
||||||
|
|
||||||
|
@ -335,5 +341,5 @@
|
||||||
|
|
||||||
*****************************************************
|
*****************************************************
|
||||||
* This is used by the shell to define $ZSH_PATCHLEVEL
|
* This is used by the shell to define $ZSH_PATCHLEVEL
|
||||||
* $Revision: 1.5760 $
|
* $Revision: 1.5761 $
|
||||||
*****************************************************
|
*****************************************************
|
||||||
|
|
|
@ -438,7 +438,7 @@ where var(term) is at least one newline or tt(;).
|
||||||
A short form of tt(select).
|
A short form of tt(select).
|
||||||
)
|
)
|
||||||
enditem()
|
enditem()
|
||||||
texinode(Reserved Words)(Comments)(Alternate Forms For Complex Commands)(Shell Grammar)
|
texinode(Reserved Words)(Errors)(Alternate Forms For Complex Commands)(Shell Grammar)
|
||||||
sect(Reserved Words)
|
sect(Reserved Words)
|
||||||
cindex(reserved words)
|
cindex(reserved words)
|
||||||
findex(disable, use of)
|
findex(disable, use of)
|
||||||
|
@ -451,7 +451,56 @@ select coproc nocorrect foreach end ! [[ { })
|
||||||
|
|
||||||
Additionally, `tt(})' is recognized in any position if neither the
|
Additionally, `tt(})' is recognized in any position if neither the
|
||||||
tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set.
|
tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set.
|
||||||
texinode(Comments)(Aliasing)(Reserved Words)(Shell Grammar)
|
texinode(Errors)(Comments)(Reserved Words)(Shell Grammar)
|
||||||
|
sect(Errors)
|
||||||
|
cindex(errors, handling of)
|
||||||
|
Certain errors are treated as fatal by the shell: in an interactive
|
||||||
|
shell, they cause control to return to the command line, and in a
|
||||||
|
non-interactive shell they cause the shell to be aborted. In older
|
||||||
|
versions of zsh, a non-interactive shell running a script would not
|
||||||
|
abort completely, but would resume execution at the next command to be
|
||||||
|
read from the script, skipping the remainder of any functions or
|
||||||
|
shell constructs such as loops or conditions; this somewhat illogical
|
||||||
|
behaviour can be recovered by setting the option tt(CONTINUE_ON_ERROR).
|
||||||
|
|
||||||
|
Fatal errors found in non-interactive shells include:
|
||||||
|
startlist()
|
||||||
|
list(Failure to parse shell options passed when invoking the shell)
|
||||||
|
list(Failure to change options with the tt(set) builtin)
|
||||||
|
list(Parse errors of all sorts, including failures to parse
|
||||||
|
mathematical expressions)
|
||||||
|
list(Failures to set or modify variable behaviour with tt(typeset),
|
||||||
|
tt(local), tt(declare), tt(export), tt(integer), tt(float))
|
||||||
|
list(Execution of incorrectly positioned loop control structures
|
||||||
|
(tt(continue), tt(break)))
|
||||||
|
list(Attempts to use regular expression with no regular expression
|
||||||
|
module available)
|
||||||
|
list(Disallowed operations when the tt(RESTRICTED) options is set)
|
||||||
|
list(Failure to create a pipe needed for a pipeline)
|
||||||
|
list(Failure to create a multio)
|
||||||
|
list(Failure to autoload a module needed for a declared shell feature)
|
||||||
|
list(Errors creating command or process substitutions)
|
||||||
|
list(Syntax errors in glob qualifiers)
|
||||||
|
list(File generation errors where not caught by the option tt(BAD_PATTERN))
|
||||||
|
list(All bad patterns used for matching within case statements)
|
||||||
|
list(File generation failures where not caused by tt(NO_MATCH) or
|
||||||
|
list(All file generation errors where the pattern was used to create a
|
||||||
|
multio)
|
||||||
|
list(Memory errors where detected by the shell)
|
||||||
|
list(Invalid subscripts to shell variables)
|
||||||
|
list(Attempts to assign read-only variables)
|
||||||
|
list(Logical errors with variables such as assignment to the wrong type)
|
||||||
|
list(Use of invalid variable names)
|
||||||
|
list(Errors in variable substitution syntax)
|
||||||
|
list(Failure to convert characters in tt($')...tt(') expressions)
|
||||||
|
similar options)
|
||||||
|
endlist()
|
||||||
|
|
||||||
|
If the tt(POSIX_BUILTINS) option is set, more errors associated with
|
||||||
|
shell builtin commands are treated as fatal, as specified by the POSIX
|
||||||
|
standard.
|
||||||
|
|
||||||
|
texinode(Comments)(Aliasing)(Errors)(Shell Grammar)
|
||||||
sect(Comments)
|
sect(Comments)
|
||||||
cindex(comments)
|
cindex(comments)
|
||||||
pindex(INTERACTIVE_COMMENTS, use of)
|
pindex(INTERACTIVE_COMMENTS, use of)
|
||||||
|
|
|
@ -1733,6 +1733,22 @@ Make the tt(echo) builtin compatible with the BSD manref(echo)(1) command.
|
||||||
This disables backslashed escape sequences in echo strings unless the
|
This disables backslashed escape sequences in echo strings unless the
|
||||||
tt(-e) option is specified.
|
tt(-e) option is specified.
|
||||||
)
|
)
|
||||||
|
pindex(CONTINUE_ON_ERROR)
|
||||||
|
pindex(NO_CONTINUE_ON_ERROR)
|
||||||
|
pindex(CONTINUEONERROR)
|
||||||
|
pindex(NOCONTINUEONERROR)
|
||||||
|
cindex(error, option to continue script on)
|
||||||
|
item(tt(CONTINUE_ON_ERROR))(
|
||||||
|
If a fatal error is encountered (see
|
||||||
|
ifnzman(noderef(Errors))\
|
||||||
|
ifzman(the section ERRORS in zmanref(zshmisc))), and the code is running
|
||||||
|
in a script, the shell will resume execution at the next statement
|
||||||
|
in the script at the top level, in other words outside all functions
|
||||||
|
or shell constructs such as loops and conditions. This mimics the
|
||||||
|
behaviour of interactive shells, where the shell returns to the
|
||||||
|
line editor to read a new command; it was the normal behaviour in versions
|
||||||
|
of zsh before 5.0.1.
|
||||||
|
)
|
||||||
pindex(CSH_JUNKIE_HISTORY)
|
pindex(CSH_JUNKIE_HISTORY)
|
||||||
pindex(NO_CSH_JUNKIE_HISTORY)
|
pindex(NO_CSH_JUNKIE_HISTORY)
|
||||||
pindex(CSHJUNKIEHISTORY)
|
pindex(CSHJUNKIEHISTORY)
|
||||||
|
|
|
@ -573,7 +573,7 @@ histsubchar(int c)
|
||||||
} else {
|
} else {
|
||||||
herrflush();
|
herrflush();
|
||||||
unqueue_signals();
|
unqueue_signals();
|
||||||
zerr("Ambiguous history reference");
|
zerr("ambiguous history reference");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1608,15 +1608,20 @@ zsh_main(UNUSED(int argc), char **argv)
|
||||||
* We only do this at top level, because if we are
|
* We only do this at top level, because if we are
|
||||||
* executing stuff we may refer to them by job pointer.
|
* executing stuff we may refer to them by job pointer.
|
||||||
*/
|
*/
|
||||||
|
int errexit = 0;
|
||||||
maybeshrinkjobtab();
|
maybeshrinkjobtab();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* Reset return from top level which gets us back here */
|
/* Reset return from top level which gets us back here */
|
||||||
retflag = 0;
|
retflag = 0;
|
||||||
loop(1,0);
|
loop(1,0);
|
||||||
|
if (errflag && !interact && !isset(CONTINUEONERROR)) {
|
||||||
|
errexit = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
} while (tok != ENDINPUT && (tok != LEXERR || isset(SHINSTDIN)));
|
} while (tok != ENDINPUT && (tok != LEXERR || isset(SHINSTDIN)));
|
||||||
if (tok == LEXERR) {
|
if (tok == LEXERR || errexit) {
|
||||||
/* Make sure a parse error exits with non-zero status */
|
/* Make sure a fatal error exits with non-zero status */
|
||||||
if (!lastval)
|
if (!lastval)
|
||||||
lastval = 1;
|
lastval = 1;
|
||||||
stopmsg = 1;
|
stopmsg = 1;
|
||||||
|
|
|
@ -113,6 +113,7 @@ static struct optname optns[] = {
|
||||||
{{NULL, "combiningchars", 0}, COMBININGCHARS},
|
{{NULL, "combiningchars", 0}, COMBININGCHARS},
|
||||||
{{NULL, "completealiases", 0}, COMPLETEALIASES},
|
{{NULL, "completealiases", 0}, COMPLETEALIASES},
|
||||||
{{NULL, "completeinword", 0}, COMPLETEINWORD},
|
{{NULL, "completeinword", 0}, COMPLETEINWORD},
|
||||||
|
{{NULL, "continueonerror", 0}, CONTINUEONERROR},
|
||||||
{{NULL, "correct", 0}, CORRECT},
|
{{NULL, "correct", 0}, CORRECT},
|
||||||
{{NULL, "correctall", 0}, CORRECTALL},
|
{{NULL, "correctall", 0}, CORRECTALL},
|
||||||
{{NULL, "cshjunkiehistory", OPT_EMULATE|OPT_CSH}, CSHJUNKIEHISTORY},
|
{{NULL, "cshjunkiehistory", OPT_EMULATE|OPT_CSH}, CSHJUNKIEHISTORY},
|
||||||
|
|
|
@ -1971,6 +1971,7 @@ enum {
|
||||||
COMPLETEINWORD,
|
COMPLETEINWORD,
|
||||||
CORRECT,
|
CORRECT,
|
||||||
CORRECTALL,
|
CORRECTALL,
|
||||||
|
CONTINUEONERROR,
|
||||||
CPRECEDENCES,
|
CPRECEDENCES,
|
||||||
CSHJUNKIEHISTORY,
|
CSHJUNKIEHISTORY,
|
||||||
CSHJUNKIELOOPS,
|
CSHJUNKIELOOPS,
|
||||||
|
|
|
@ -419,26 +419,26 @@
|
||||||
>output
|
>output
|
||||||
?zsh:.:2: no such file or directory: /nonexistent/nonexistent
|
?zsh:.:2: no such file or directory: /nonexistent/nonexistent
|
||||||
|
|
||||||
|
$ZTST_testdir/../Src/zsh -f -o CONTINUE_ON_ERROR <<<'
|
||||||
|
readonly foo
|
||||||
|
foo=bar set output
|
||||||
|
echo output'
|
||||||
|
0:failed assignment on posix special, CONTINUE_ON_ERROR
|
||||||
|
>output
|
||||||
|
?zsh: read-only variable: foo
|
||||||
|
|
||||||
$ZTST_testdir/../Src/zsh -f <<<'
|
$ZTST_testdir/../Src/zsh -f <<<'
|
||||||
readonly foo
|
readonly foo
|
||||||
foo=bar set output
|
foo=bar set output
|
||||||
echo output'
|
echo output'
|
||||||
0:failed assignment on posix special, NO_POSIX_BUILTINS
|
1:failed assignment on posix special, NO_CONTINUE_ON_ERROR
|
||||||
>output
|
|
||||||
?zsh: read-only variable: foo
|
?zsh: read-only variable: foo
|
||||||
|
|
||||||
$ZTST_testdir/../Src/zsh -f -o POSIX_BUILTINS <<<'
|
$ZTST_testdir/../Src/zsh -f -o CONTINUE_ON_ERROR <<<'
|
||||||
readonly foo
|
|
||||||
foo=bar set output
|
|
||||||
echo output'
|
|
||||||
1:failed assignment on posix special, POSIX_BUILTINS
|
|
||||||
?zsh: read-only variable: foo
|
|
||||||
|
|
||||||
$ZTST_testdir/../Src/zsh -f -o POSIX_BUILTINS <<<'
|
|
||||||
readonly foo
|
readonly foo
|
||||||
foo=bar echo output
|
foo=bar echo output
|
||||||
echo output'
|
echo output'
|
||||||
0:failed assignment on non-posix-special, POSIX_BUILTINS
|
0:failed assignment on non-posix-special, CONTINUE_ON_ERROR
|
||||||
>output
|
>output
|
||||||
?zsh: read-only variable: foo
|
?zsh: read-only variable: foo
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue