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


Groups > gnu.bash.bug > #16708

Re: process substitution error handling

Path csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Eli Schwartz <eschwartz@archlinux.org>
Newsgroups gnu.bash.bug
Subject Re: process substitution error handling
Date Thu, 6 Aug 2020 08:33:01 -0400
Lines 101
Approved bug-bash@gnu.org
Message-ID <mailman.986.1596717206.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>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="S7i97yhLsycTm0isQrrxXsdDBARZ4SkpY"
X-Trace usenet.stanford.edu 1596717206 30605 209.51.188.17 (6 Aug 2020 12:33:26 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
X-Spam-BL-Results
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1596717190; bh=aoAaSEjUA/p+2gssZlbEI1DbcIW9qSaOp15w/XAGWEE=; h=Subject:To:References:From:Date:In-Reply-To; b=uOVCUHEcfxnylWXSllrM/Fu7+XOJMzdru4lLWugZHcFTDKowMKUskGnd6WJkhxC3n SVElkBE3tWf1vEAU5bxmnU5uugAl4d0DrK7D6EJXQZ0xnMZE89hVK0QqL6bbKQzK0Z 7A0zihKAy/MWwO5lZBKlp9bSUYzrXODmnFrv1v3w5VvtYsj4d7szNh4fzM9wp+ipH9 E9cJJSGTv4r3e+MkokWMuzAaBcAqZfyeUdMzUMc/zTBLJcocByWIJA6bCBOEMSzyYK gDi8EIaytiKVhDekwaQfldAqclN6Oyzk53vJ7kE6uCSb6OBGwd3G68y3LpRqnFIgaJ R9c1DUZTsmGeS5QmNH/8c9ku7azXELhGB61DjpTPJ+TyF67GPS2WCz8gxRJ9D1y1Tu MgBVKgb98ssA8VSutqeLfd8CoCgfAE4zZ4FpVmWB8PWlZ8MzzFg884u5iK75xbkntg mCIl6gxIMCkxH6BhMlBvzE1nJDTiagxo3AvFDjvQzbrUDalMHlgXySmQ08QSnRwV/d Nsw90kruhevL7CsEXzpPoQBsFynOpDrorPSj6auie53apLs4QCqlBXXwbeSzbhPFhn 4s1N1gKNsHa1JCGtGCQ0JOgEX1GoK+k6zlHEjd5eLmj5SGdJjzaYwCZOOCcFZ/4bNI xSfa9KPqRilW6lrARf5IrCaI=
X-Clacks-Overhead GNU Terry Pratchett
In-Reply-To <CAHmME9pzOY_0EJ69y9wt6r-Jh3frZpV8XdFC6zG5EOkZ99h-1A@mail.gmail.com>
Received-SPF pass client-ip=2a01:4f8:160:6087::1; envelope-from=eschwartz@archlinux.org; helo=orion.archlinux.org
X-detected-operating-system by eggs.gnu.org: No matching host in p0f cache. That's all we know.
X-Spam_score_int -53
X-Spam_score -5.4
X-Spam_bar -----
X-Spam_report (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no
X-Spam_action no action
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <e0a56db4-6444-5dde-3fdc-e3237e669cc6@archlinux.org>
X-Mailman-Original-References <20200420051508.GA2359844@zx2c4.com> <7496b183-2db3-6c03-6074-928adcd08f45@case.edu> <CAHmME9pzOY_0EJ69y9wt6r-Jh3frZpV8XdFC6zG5EOkZ99h-1A@mail.gmail.com>
Xref csiph.com gnu.bash.bug:16708

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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 $?"

> 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.

-- 
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User

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


Thread

Re: process substitution error handling Eli Schwartz <eschwartz@archlinux.org> - 2020-08-06 08:33 -0400

csiph-web