zsh-users
 help / color / mirror / code / Atom feed
* parse vs. runtime errors
@ 2018-04-20 18:00 Ray Andrews
  2018-04-20 19:00 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Ray Andrews @ 2018-04-20 18:00 UTC (permalink / raw)
  To: Zsh Users

How come:

[ .... ]]

is only caught as an error at runtime?  The error kills anything 
remaining on the same line, but subsequent linesexecute as normal.  I 
find most errors kill the entire parse, but there are some few that 
survive parse but throw the error at runtime.  Why is that?  It's a bit 
annoying that the runtime error can be buried in output and so not be 
noticed, and it seems like it would have to be an error at parse too.  
Either way, can I ask zsh to always make any error stop everything and 
make itself known?  I'll often do something like:

$ . func-file; func arg1 arg2

... and if 'func-file' has some bug in the contained source of 'func 
()', the older version of 'func' just runs anway and one does not see 
the error messageif the output scrolls off the screen.  True, one might 
not be so lazy and source the file, then run the command, but still it 
would be nice if there was some way of making zsh always stop whatever 
it is doing when any code error shows up.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: parse vs. runtime errors
  2018-04-20 18:00 parse vs. runtime errors Ray Andrews
@ 2018-04-20 19:00 ` Bart Schaefer
  2018-04-21  1:48   ` Ray Andrews
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2018-04-20 19:00 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 592 bytes --]

On Fri, Apr 20, 2018, 11:31 AM Ray Andrews <rayandrews@eastlink.ca> wrote:

> How come:
>
> [ .... ]]
>
> is only caught as an error at runtime?


"[" is a command (synonym for "test") and not a token, and "]]" is only a
token when balanced with "[[".

  The error kills anything
> remaining on the same line


That would depend on how the remaining commands are separated from this one.

Either way, can I ask zsh to always make any error stop everything and
> make itself known?


That's what "setopt errexit" is for, although that mostly applies to
scripts rather than interactive shells.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: parse vs. runtime errors
  2018-04-20 19:00 ` Bart Schaefer
@ 2018-04-21  1:48   ` Ray Andrews
  0 siblings, 0 replies; 3+ messages in thread
From: Ray Andrews @ 2018-04-21  1:48 UTC (permalink / raw)
  To: zsh-users

On 20/04/18 12:00 PM, Bart Schaefer wrote:
> On Fri, Apr 20, 2018, 11:31 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
>
> "[" is a command (synonym for "test") and not a token, and "]]" is only a
> token when balanced with "[[".
Probably way over my head.  I expect the former goes back to the 
beginning of shells so is written in stone.  The latter seems 
'obviously' strange so  I expect there's a good reason for it, but it 
sure is counter intuitive.  Still, why/how can it be acceptable at parse 
but not at run?  Perhaps because it is theoretically 
completeable/resolvable at parse but in practice turns out to be a dead 
end at run?  That is, one might write something that ends up with that 
construction not being an error? at runtime?
>
> That's what "setopt errexit" is for, although that mostly applies to
> scripts rather than interactive shells.
>
Yeah, no luck:

test1 ()
{

setopt errexit
[ "$1" = 'two' ]] && echo that was two
echo that was three

}

16 /aWorking/Zsh/Source/Wk 3 $ . test

16 /aWorking/Zsh/Source/Wk 3 $ test1 two
test1:[:4: ']' expected
that was three

... so it didn't abort the function.  Any other way?



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-04-21  1:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-20 18:00 parse vs. runtime errors Ray Andrews
2018-04-20 19:00 ` Bart Schaefer
2018-04-21  1:48   ` Ray Andrews

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).