Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16711

Re: process substitution error handling

From "" <kfm@plushkava.net>
Newsgroups gnu.bash.bug
Subject Re: process substitution error handling
Date 2020-08-06 14:15 +0100
Message-ID <mailman.994.1596719749.2739.bug-bash@gnu.org> (permalink)
References <20200420051508.GA2359844@zx2c4.com> <7496b183-2db3-6c03-6074-928adcd08f45@case.edu> <CAHmME9pzOY_0EJ69y9wt6r-Jh3frZpV8XdFC6zG5EOkZ99h-1A@mail.gmail.com> <e0a56db4-6444-5dde-3fdc-e3237e669cc6@archlinux.org> <8a54cb1e-af78-f79f-6d73-6a235d707207@plushkava.net>

Show all headers | View raw


On 06/08/2020 13:33, Eli Schwartz wrote:
> On 8/6/20 6:05 AM, Jason A. Donenfeld wrote:
>> Hi,
>>
>> It may be a surprise to some that this code here winds up printing
>> "done", always:
>>
>> $ cat a.bash
>> set -e -o pipefail
>> while read -r line; do
>>         echo "$line"
>> done < <(echo 1; sleep 1; echo 2; sleep 1; false; exit 1)
>> sleep 1
>> echo done
>>
>> $ bash a.bash
>> 1
>> 2
>> done
>>
>> The reason for this is that process substitution right now does not
>> propagate errors.
> 
> Well, yes, it is an async command. But errexit has lots of other amusing
> traps, like
> 
> $ echo $(false)
> 
>> It's sort of possible to almost make this better
>> with `|| kill $$` or some variant, and trap handlers, but that's very
>> clunky and fraught with its own problems.
>>
>> Therefore, I propose a `set -o substfail` option for the upcoming bash
>> 5.1, which would cause process substitution to propagate its errors
>> upwards, even if done asynchronously.
> 
> Propagate the return value of async processes like this:
> 
> wait $! || die "async command failed with return status $?"

You beat me to it. I was just about to suggest wait $! || exit. Indeed, 
I mentioned the same in a recent bug report against wireguard-tools.

> 
>> It'd certainly make a lot of my scripts more reliable.
> 
> The use of errexit is the focus of a long-running holy war. Detractors
> would point out a very lengthy list of reasons why it's conceptually
> broken by design. Some of those reasons are documented here (including
> process substitution): http://mywiki.wooledge.org/BashFAQ/105
> 
> I recommend you do NOT claim this feature is a magic panacea that will
> make your scripts reliable; instead, just say you would find it useful.
>

I concur. The scripts I looked at tended heavily towards error handling 
at a distance and were already subject to one or two amusing errexit 
pitfalls.

-- 
Kerin Millar

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: process substitution error handling "" <kfm@plushkava.net> - 2020-08-06 14:15 +0100

csiph-web