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 12:21:34 -0400 Lines: 121 Approved: bug-bash@gnu.org Message-ID: References: <20200420051508.GA2359844@zx2c4.com> <7496b183-2db3-6c03-6074-928adcd08f45@case.edu> <9b358a76-4867-41b9-5a3a-c1892c76b8ee@case.edu> <917bf529-d3cb-6783-326b-c7baa7ca9a2e@archlinux.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mIW73o68nUF1zP53wolF7VFhTLx5Mz6Uh" X-Trace: usenet.stanford.edu 1596730913 7040 209.51.188.17 (6 Aug 2020 16:21:53 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=1596730899; bh=NZtQh5PG8OTRj2pciN8AF+C1E25ARSBGxFJEdhtdIfE=; h=Subject:To:References:From:Date:In-Reply-To; b=YNdoOkdbbBzAuTlnFA+APi5czCuhHfxwoNJ2vrBgO9nlEGawo+PgZy8TjEbYOsX3P N/zOhNiYrzxnONXiLQeCcZN1D+m5NcnoN5ZbKZJL+dyyEn9hM9807Nx245kRGBKF3c uiy70SOKTiRylNHgHDuygF65wymKNVVzxodo5dNbVv/z1qLwXjoGkF5uGOZOpC1dT6 8kCfZpZTyhl/vTHn+eo7/xA8oGsUzdYfPaSDfyMfoisccXY6wRZgSA9W6MrXUsS1VR mGJo4WEhKml/S4lXPLzSX8c5pfG/UPWFAGfFOyJ5lXdeOvGUbF0iyCg32CVWerhe8I GsHo5GoesbtH4eNCLYRP1NeTEUrqONgJq1d+3nnKGRREJ66rGJplY17gGp3S3wHuL2 aVhI8ey1axPm13hg9hV9XOZCssqXIzp+Dlqup5POsIWx//fW4diLb1mwxtjc5rtmJm RZyD2BHWTTs8rW3T7jRaZhFnEaJlWRjuxzCAPDQtW7D2NJrLk6UFZM2SfQNTJZ0Yna cIJMwmWf5fOUBkkHORCuvG2ZW27hjlGiJ8PLC7rvTKPHSXWJKGFDnL3anDSHw2Vm77 6JWz2akxj/1dVPFPn1ze05O7CCJAGxcaxZqeLM7/ZthJKQQjPzUYfAps3nZMUAjKol aEKVKgp4L0aix5TrAzK5Bb3A= X-Clacks-Overhead: GNU Terry Pratchett In-Reply-To: Received-SPF: pass client-ip=88.198.91.70; envelope-from=eschwartz@archlinux.org; helo=orion.archlinux.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/06 12:21:41 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: <917bf529-d3cb-6783-326b-c7baa7ca9a2e@archlinux.org> X-Mailman-Original-References: <20200420051508.GA2359844@zx2c4.com> <7496b183-2db3-6c03-6074-928adcd08f45@case.edu> <9b358a76-4867-41b9-5a3a-c1892c76b8ee@case.edu> Xref: csiph.com gnu.bash.bug:16721 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --mIW73o68nUF1zP53wolF7VFhTLx5Mz6Uh Content-Type: multipart/mixed; boundary="eoikx6X3OQaBkHbHD9g1oHEASvqBBDhua" --eoikx6X3OQaBkHbHD9g1oHEASvqBBDhua Content-Type: text/plain; charset=utf-8 Content-Language: en-US-large Content-Transfer-Encoding: quoted-printable On 8/6/20 11:31 AM, Jason A. Donenfeld wrote: > That doesn't always work: >=20 > set -e > while read -r line; do > echo "$line" & > done < <(echo 1; sleep 1; echo 2; sleep 1; exit 77) > sleep 1 > wait $! > echo done So instead of your contrived case, write it properly. Check the process substitution first, and make sure as a bonus you don't run anything if if it failed: set -e mapfile -t lines < <(echo 1; sleep 1; echo 2; sleep 1; exit 77) wait $! for line in "${lines[@]}"; do echo "$line" & sleep 1 wait $! echo done (And in bash 5.1 you can remember each &'ed command to wait on later.) > Either way, tagging on `wait $!` everywhere, and hoping it works like > I want feels pretty flimsy. Are you sure you're opposed to set -o > procsuberr that would do the right thing for most common use cases? You're asking to add broken behavior which does the wrong thing in bizarre, outrageous ways in many cases. Your rationale is it works in your specific case, and you have a mysterious aversion to wait $! which you haven't explained. (Why is it flimsy? It performs exactly as documented.) I think the problem here is twofold: You have an emotional attachment to errexit and you think it solves problems, so you want to turn everything into it. Ultimately, you really don't have issues with "flimsy" anything, but you want bash to be a different language, one with a formal exception model, strong types, and possibly objects. Such a language would then react to *programmer errors* by failing to compile, or dumping a traceback of the call site, and could be used as a beginner-friendly language that doesn't surprise the newbies. There are a number of good languages like that. Shell isn't one of them. Sometimes you need to understand how edge cases work. Nevertheless, there are ways to code robustly in it. In another language, you'd run forked commands upfront and save their results to some sort of object or variable, and only then process it (after checking the return code or using a function that automatically raises exceptions on failure). You can do that in bash too, as I demonstrated with mapfile and wait $! It isn't really a terrible disadvantage that you need more characters to type out your intent. Most particularly when your intent is "I want this command to run async, but I also want it to exit the script at XXX location if previous aysnc commands have failed". You cannot really get around explicitly tagging the place where you want to raise errors. Using an RNG to randomly raise the error automatically at unpredictable locations isn't a valuable feature to add. --=20 Eli Schwartz Arch Linux Bug Wrangler and Trusted User --eoikx6X3OQaBkHbHD9g1oHEASvqBBDhua-- --mIW73o68nUF1zP53wolF7VFhTLx5Mz6Uh Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEvSewel70XCra9w4EhIGKaBmvSpsFAl8sLg4ACgkQhIGKaBmv Spuddg/9E9hASU6gcQfnXY03AGUp4ZVeez9vfkKROcan50DM5DA+TY6oSQg/jch6 fx1FbzwPJDwN5MQ4MhEhPw+gtf3sBsQIyZ+2G6T3/kOBIOz+i5GWItNXXEREQ0NL tdEfiduqDuO/sq0HnLSk8I53y34D0NRkyttIRBvGFt76XD6LitgmZztBrsFD1URX 2VfaTz3MAxFmErJ0ww0h2ecjzT4aKQOLmo+90rpypZHWNomOSZ3NoqhDM7IsTYb+ ufPFGG5YWDyyXo83pgXBKbTcthZMrVdz6cNg52dr4SNBoVbAlvXNq+fB7EJN0jpM NQm8BdqUXB1KrKXn1Tygj10a0H5iVnM55jqEv1jEKjnjWOFD7NdLbC2nO0NxJwT8 abIhC2cA2TYG+yKXpsJAuEuKEZzPPW/WQ1rp5XZbcUZDQspZ+1ofLr+mlkIcmsbE ObABE7i4tM3AwU6sYEHqycYY1KyON7I+dL03QmiwjNwcTfc4HxAJStU1gFZt7x/m jbOf+EjCC7aJV0mMk/gfZL9WJpMOCeT8F/ApaW7jwoaIEC/D/ZkSP+XSv6wpGR/L y6weksOA4feX1mfYewhE2Nv94IVQczLvuxtUKGptTiYEg9JF3i+q/RfkoAkc/AVh WeHGopy/nNyLydNTNU2DYD9dyvQoEYgxMMsNtXpjNszJduC9VUWJAjMEAQEKAB0W IQRgQRMEwJ02YoNA7v/OsWfvtXIr1gUCXywuDgAKCRDOsWfvtXIr1rynD/9Giqq2 43T6X6expdFPtllYvX5L8M3XmWgmpEthfwdsN5Sdi1VuH+eiIxtTBJpO469/qSKU MzrEezYK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