Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Weird exit caused in a trap DEBUG which sources a file.



Comments in line.

On Sun, Aug 3, 2008 at 6:42 AM, Peter Stephenson
<p.w.stephenson@xxxxxxxxxxxx> wrote:
> On Sat, 2 Aug 2008 07:21:43 -0400
> "Rocky Bernstein" <rocky.bernstein@xxxxxxxxx> wrote:
>>
>> It may be useful to have some "trap DEBUG" exit codes alter program
>> flow. For example in bash if "trap DEBUG" returns 2, then if you are
>> inside a function that does an immediate return from the function
>> (implementing a gdb "return" command).
>
> This happens on any explicit "return" from a non-function trap.
>
>> It might also be nice to have a "trap DEBUG" exit value which
>> indicates that the next command is skipped rather than executed.
>
> That's a little more tricky:  it's not very clear what the next command
> actually is if it's a complicated expression.  Looking at the code, it's
> not hard to do something here, but making it properly consistent is
> another matter.  I think it would probably work if done at the level of
> commands separated by semicolons, newlines or ampersands (described
> internally as sublists).

I do not see why this is semantically complicated when the trap DEBUG
occurs before the statement it refers to is run.  Can you give a very
specific example of something you feel is tricky?

>
>> And since I brought up "trap DEBUG" execution order again, at the risk
>> of beating a dead horse...
>
> I don't really understand what the issue is.  Is there something about
> the DEBUG_BEFORE_CMD option that makes it hard to ensure it is set at
> the right point (this is not a trick question, that's perfectly
> possible)?

David Korn made a mistake and he says so.  Chet Ramey also says he
changed the behavior because he thought it a mistake too. zsh copied
the mistake. The only claim I've heard for keeping the mistake is
compatibility with previous versions of zsh. However right now there
is no evidence that anyone is making use of this mistake that would
not be happier if it weren't made.  When this mistake was corrected in
bash and ksh, no complaint was registered to keep the old less-helpful
behavior.

Generally one thinks of the default value as the thing most people
would choose. Compatibility is a good thing, but using it as an
argument for keeping a mistake that no one is using, seems to me to be
blindly following a rule without understanding why the rule is there.

So the suggestion is changing the default behavior to something which
follows both bash and ksh of the last 6 or so years.  If nothing else,
both bash and sh emulation in zsh should make this default behavior.

Thanks.



Messages sorted by: Reverse Date, Date, Thread, Author