zsh-users
 help / color / mirror / code / Atom feed
From: Zach Riggle <zachriggle@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Accessing the evaluated expression which caused an error
Date: Fri, 3 Sep 2021 12:38:12 -0500	[thread overview]
Message-ID: <CAMP9c5ncfwHjWMaFuf=u6WhvNiN_UqMMArxtmHt4A+HqFMN0NA@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7aT6rgWDnfr0A=j7nrv2PjQMDJddefRhTg_VrmU2YF_6w@mail.gmail.com>

> What exactly might you want captured?

Very frequently I build a create an array that contains a command, e.g.

    declare -a cmd=( echo hello world )

And invoke it like:

    "${cmd[@]}"

When I xtrace, it will print out the values inside the array.

    +wat.sh:2> cmd=( echo hello world )
    +wat.sh:3> echo hello world

With TRAPDEBUG or TRAPERR, all I get is the "${cmd[@]}". None of the
Zsh-supplied arrays (funcfilesource etc.) contain that.  I originally
had some hope that $_ would work, but it appears not to.

Zach Riggle

On Fri, Sep 3, 2021 at 12:14 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> On Thu, Sep 2, 2021 at 6:43 PM Zach Riggle <zachriggle@gmail.com> wrote:
> >
> > I'm aware of funcsourcetrace, funcstack, and TRAPDEBUG /
> > ZSH_DEBUG_CMD as well, but none of these contain the actual expression
> > evaluated -- just the input to zsh.
> >
> > I know that zsh has the data internally, since "zsh -x" shows the
> > fully-evaluated expression, so that data must be available somewhere,
> > even if it's not exposed in a shell variable.
>
> Hm.  What xtrace does is dump each individual shell word ... it just
> happens to dump them in the order that puts them together as an
> "expression".  But you'll notice it's not actually an expression, it's
> just e.g. a single simple command.  In fact it's even a bit weird for
> some structured commands (look at the output for a "case" statement
> for example).
>
> It's correct that none of this is captured in any sort of format that
> would be usable by a shell script.  It never exists all at once in
> such a format internally.
>
> What exactly might you want captured?


  reply	other threads:[~2021-09-03 17:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-03  1:42 Zach Riggle
2021-09-03 17:14 ` Bart Schaefer
2021-09-03 17:38   ` Zach Riggle [this message]
2021-09-04 20:08     ` Bart Schaefer
2021-09-05  0:26       ` Zach Riggle
2021-09-05  1:44         ` Lawrence Velázquez
2021-09-05  2:08         ` Bart Schaefer

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='CAMP9c5ncfwHjWMaFuf=u6WhvNiN_UqMMArxtmHt4A+HqFMN0NA@mail.gmail.com' \
    --to=zachriggle@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@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).