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

Re: PATCH: skip command from debug trap



On Aug 7, 11:11am, Peter Stephenson wrote:
} Subject: Re: PATCH: skip command from debug trap
}
} On Wed, 06 Aug 2008 18:00:10 -0700
} Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > 
} > 	TRAPDEBUG() { return 1 }
} > 	setopt DEBUG_BEFORE_CMD IGNORE_EOF
} > 
} > You've just rendered your shell useless.  You can't even exit from it
} > (except by way of the ten-EOFs failsafe we put in some while ago).
} 
} I suppose that's power vs. responsibility.

One point:  This becomes even easier to screw up if DEBUG_BEFORE_CMD is
the default behavior, and would be mystifying to a typical user.
 
} > I propose that ERR_EXIT be unset on entry to TRAPDEBUG, always.  Then at
} > return from the function, if ERR_EXIT has become set, treat that as an
} > indication to skip the command (and restore ERR_EXIT to whatever its
} > pre-function state was).

After sending this I thought "hmm, I could just as easily have suggested
a new option."  I guess it's a good thing I didn't.

} > If you setopt ERR_EXIT and return non-zero
} > you still get what you always would (anyway, if you really wanted the
} > shell to exit, you can just call "exit" from the trap).
} 
} This seems quite neat, it even gets round the nastiness of working out
} which level of the function call stack your at to fiddle with the return
} value.  It seems perfectly reasonable to make non-use of ERR_EXIT within
} DEBUG traps a documented feature:  we already do this during initialisation
} scripts and can invoke the same mechanism trivially here.  That's not quite
} what you said---you said let it behave as normal but with the additional
} feature, but given we have the other mechanism to suppress its use, it
} seems neater to apply that here when hijacking the option, right?

Yes; in fact when I first wrote it down I suggested exactly that, but
then noticed that it wasn't necessary to disable it entirely and backed
out that part.  If it's actually *easier* this way, the "you can just
call 'exit'" still applies.



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