Path: csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Eli Schwartz 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: References: <20200420051508.GA2359844@zx2c4.com> <7496b183-2db3-6c03-6074-928adcd08f45@case.edu> 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <20200420051508.GA2359844@zx2c4.com> <7496b183-2db3-6c03-6074-928adcd08f45@case.edu> Xref: csiph.com gnu.bash.bug:16708 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --S7i97yhLsycTm0isQrrxXsdDBARZ4SkpY Content-Type: multipart/mixed; boundary="netrf2JgYuSUyri6MkzaGz11JSOWKJdCJ" --netrf2JgYuSUyri6MkzaGz11JSOWKJdCJ Content-Type: text/plain; charset=utf-8 Content-Language: en-US-large Content-Transfer-Encoding: quoted-printable On 8/6/20 6:05 AM, Jason A. Donenfeld wrote: > Hi, >=20 > It may be a surprise to some that this code here winds up printing > "done", always: >=20 > $ 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 >=20 > $ bash a.bash > 1 > 2 > done >=20 > 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. >=20 > 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. --=20 Eli Schwartz Arch Linux Bug Wrangler and Trusted User --netrf2JgYuSUyri6MkzaGz11JSOWKJdCJ-- --S7i97yhLsycTm0isQrrxXsdDBARZ4SkpY Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEvSewel70XCra9w4EhIGKaBmvSpsFAl8r+H4ACgkQhIGKaBmv SptPgRAAt3Ff3b3VlDbo5OiuDLKdObBVAKCLfW94yAkWF09v22hgpgURGeHmFpfg laHjFgOZ3LauDnC740XgqlImYKyMt2uWCugsqG/Ki7jJSS6F38JNUjvM0D6hiLOJ sLifObXmNT4tKwu84gRGDIfx5SGxiJDVynOKVrihNjNg1PdjuoHkUFoxYCBMKOJA TZMSvZlL2CLw6h92TLxN6vS5CBIE09YNjNtf8G/zfZKWRYqUt8qVYH8mV5adAXIK 3mhAiVv1GsaPzQLnNu7rXhXwuuudOkwuF08vf1rNmCMWBvrXchy4ILoT0hJ8FKJ+ zNW69iQHh1dBTOew9qD1hlN+4LgI2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