From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11925 invoked by alias); 30 Dec 2012 21:33:12 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17512 Received: (qmail 7956 invoked from network); 30 Dec 2012 21:33:02 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <121230133257.ZM1210@torch.brasslantern.com> Date: Sun, 30 Dec 2012 13:32:57 -0800 In-reply-to: Comments: In reply to Russell Harmon "Re: err_return inside function who's return value is checked" (Dec 30, 3:55pm) References: <121230113526.ZM967@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: err_return inside function who's return value is checked MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Dec 30, 3:55pm, Russell Harmon wrote: } } On Sun, Dec 30, 2012 at 2:35 PM, Bart Schaefer } wrote: } > This obviously is a case where err_return might be permitted to behave } > differently without causing too much consternation, but that's not how } > it has been defined. } } Can this be arranged? Anything's possible. :-) I'm not personally very familiar with this part of the internals, so I'm not sure how difficult it would be. However ... } It would enable idioms like the following to be used: } } function get_major_version { } setopt err_return } [[ $(program -V) =~ "version ([[:digit:]]+)\." ]] } REPLY=$match[1] } } This isn't really what err_return (or err_exit) is meant for. If you have cases where you are *expecting* the command to fail, you should be able to write [[ $(program -V) =~ "version ([[:digit:]]+)\." ]] || return just as easily. Instead, err_return is intended to trap unexpected failures, or conditions that occur so rarely that it over-complicates the flow of control to constantly test $? after each command. E.g., suppose you're calling a function someone else wrote. Somewhere in that function is a "chmod" command, which is never expected to fail (it's return status isn't tested) but if it does fail it'll leave a security hole in its wake. So *outside* of that function you setopt err_return to force it to stop if the chmod does not work. (Of course the above would lead to the argument that "emulate" should not mess with err_exit/err_return.)