Re: [RFC] Logically composable variant of errexit
2014-10-10 3:29 GMT+02:00 Chet Ramey chet.ra...@case.edu: What does logically composable mean in this context? I would like the hypothetical errfail option to: * Behave like errexit at the top level (outside of functions). * Be inherited by functions, subshells, and command substitution. * Inside functions, it should trigger like errexit would outside of functions, no matter how the function is called. It should return instead of exiting, though. With errexit, you get vastly different results from functions depending on how the functions are called, for example, foo() { echo foo: top false echo foo: bottom } set -o errexit # bottom of foo reached: if foo; then echo success # reached fi # bottom of foo not reached: foo With errfail, foo:bottom and success would not be reached. Command substitutions would continue to behave as basic commands do with respect to control flow: inside functions, a failure would cause the function to return; outside of functions, the script would exit. Thanks, Andreas
Re: [RFC] Logically composable variant of errexit
2014-10-10 8:38 GMT+02:00 Dan Douglas orm...@gmail.com: I would still propose that a simple and powerful way to extend Bash with exception handling would be to extend the ERR trap by passing it some metadata about the type and location of the exception incurred so that it can be handled by user code. This proposal allows us to largely avoid having to answer the question of when and where does it make sense for this to get triggered? for the user. It might require a new type of trap that just fires on anything that returns false or fails so that the user handler can choose what to do about it in various contexts. Well, currently, the ERR trap only triggers when errexit would trigger, so another type of trap would certainly be needed. I don't think it's reasonable to expect from users to use trigger tricks to get basic error handling working in a sane way, though; this should be built in and trivial to activate. Thanks, Andreas
[RFC] Logically composable variant of errexit
Hi all, the errexit option can be very useful in simple scripts. This option is being ignored in many contexts like lists and conditionals though. I understand that this is by design and that errexit cannot be fixed to behave more reasonably. Still, this makes bash a lot less useful than it could be; working around this limitation is painful, ugly, and leads to fragile code. So, since we cannot fix errexit, can we maybe introduce another option like errfail that behaves like errexit for simple commands, but is also logically composable? Let me show what I mean with the following pseudo-code: set -o errfail fail() { false echo 'oops!' 2 # not reached } ! fail fail || : if fail; then : fi set -- `fail` # script fails here echo 'oops!' 2 # not reached Having such an option would certainly make bash a lot more useful to me. What do you guys think, could such an option be implemented with reasonable effort? Thanks, Andreas