zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH] typeset: set $? on incidental error
Date: Fri, 29 Jan 2016 09:18:34 +0000	[thread overview]
Message-ID: <20160129091834.GA8420@tarsus.local2> (raw)
In-Reply-To: <160126201724.ZM2552@torch.brasslantern.com>

Bart Schaefer wrote on Tue, Jan 26, 2016 at 20:17:24 -0800:
> On Jan 26, 10:50pm, Daniel Shahaf wrote:
> }
> } If existing typesets always exit zero in the circumstance that the patch
> } proposes to change, no code would be broken by this change (no existing
> } code, no new zsh-targeted code, no new ksh-targeted code), except for
> } new ksh-targeted code written by zsh users who won't be aware of this
> } difference.
> 
> This is not true.  Scripts using "setopt errexit" or "setopt errreturn"
> or "set -e" will fail in ways they did not fail before.

Scripts using errexit would have a new early-out failure mode.  I think
taking the new early-out would, at least in some cases, be the right
thing to do: it may be better to abort than to process invalid or
incomplete data.  I agree that it might be a bug in other cases.

All that said, I suppose we may as well stop here: it's clear the
original patch isn't on the verge of being applied.  How about a docs
patch instead, to point out the difference in behaviour? —

diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index fb630a7..6e3d146 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -1826,6 +1826,23 @@ reserved word interface for tt(typeset) may cause problems with the
 output of `tt(typeset -p)', which assumes the reserved word interface is
 available in order to restore array and associative array values.
 
+Unlike parameter assignment statements, tt(typeset)'s exit status on an
+assignment that involves a command substitution does not reflect the exit
+status of the command substitution.  Therefore, to test for an error in
+a command substitution, separate the declaration of the parameter from its
+initialization:
+
+example(# WRONG
+typeset var1=$(exit 1) || echo "Trouble with var1"
+
+# RIGHT
+typeset var1 && var1=$(exit 1) || echo "Trouble with var1"
+)
+
+To initialize a parameter var(param) to a command output and mark it readonly,
+use tt(typeset -r )var(param) or tt(readonly )var(param) after the parameter
+assignment statement.
+
 If the shell option tt(TYPESET_SILENT) is not set, for each remaining
 var(name) that refers to a parameter that is already set, the name and
 value of the parameter are printed in the form of an assignment.

Cheers,

Daniel


  reply	other threads:[~2016-01-29  9:18 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14  0:13 Daniel Shahaf
2016-01-14  4:58 ` Bart Schaefer
2016-01-14  5:24 ` Eric Cook
2016-01-15  6:26   ` Daniel Shahaf
2016-01-15 14:46     ` Mikael Magnusson
2016-01-15 14:54       ` Eric Cook
2016-01-15 15:49         ` Peter Stephenson
     [not found]       ` <20160118022557.GE3979@tarsus.local2>
2016-01-18  4:38         ` Mikael Magnusson
2016-01-18 13:33           ` Mikael Magnusson
2016-01-20  7:47           ` Daniel Shahaf
2016-01-20 15:00             ` Eric Cook
2016-01-23 23:53               ` Daniel Shahaf
2016-01-24  3:32                 ` Eric Cook
2016-01-26 22:50                   ` Daniel Shahaf
2016-01-27  4:15                     ` Error status of "repeat" (was Re: [PATCH] typeset: set $? on incidental error) Bart Schaefer
2016-01-27  4:38                       ` Bart Schaefer
2016-01-27  9:52                       ` Peter Stephenson
2016-01-29  9:18                         ` Daniel Shahaf
2016-01-29  9:29                           ` Peter Stephenson
2016-01-29 10:25                             ` Daniel Shahaf
2016-01-27  4:17                     ` [PATCH] typeset: set $? on incidental error Bart Schaefer
2016-01-29  9:18                       ` Daniel Shahaf [this message]
2016-01-30  7:46                         ` typeset docs flow " Daniel Shahaf
2016-01-30 19:47                           ` Bart Schaefer
2016-01-31  0:49                             ` Jun T.
2016-01-31 17:03                               ` Bart Schaefer
2016-02-01  3:23                                 ` Jun T.
2016-02-01  5:41                                   ` Bart Schaefer
2016-01-21 14:22             ` Vincent Lefevre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160129091834.GA8420@tarsus.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).