Skip to content

How to debug  #177

Closed
Closed

Description

@shah

Hi @romkatv and team, I've been using your fantastic z4h project for a while and I wanted to thank you for the fantastic product. For many months I've had no issues but something weird now happens every once in a while. I was curious if you have ideas about how to I should debug this intermittent message:

^[[>0;10;1c(anon):43: bad math expression: operand expected at `>0'
snshah@wsllocal /
  %                                                                                                   z4h recovery mode

I'm running on Debian 11 WSL2 VM in Windows 11 and many times a day when I open a terminal I get the message above. I'm using a "stock" z4h setup and when I run z4h update the error message goes away. Then, when I open a new terminal sometimes I do not get the message but other times I do see the message. Anytime I do see the message, running z4h update in that terminal will fix everything but then, later, when I open a new terminal sometimes the problem reappears.

I figured that since z4h has gone into recovery mode perhaps there's some debugging I can do to figure out which file (anon):43 refers to. There are times when no messages appear and all is good but then there are times when the exact same message as above appears on the same (anon):43.

I have not figured out how to reproduce the problem so this ticket is really mostly a request for ideas about how to do debugging. :-)

Keep up the great work!

Activity

  1. romkatv commented on Nov 22, 2021

    @romkatv
    Owner

    This is a third report I'm getting about something being broken in a severe and weird way on Windows 11. Your report is the first with this error.

    Does exec zsh fix your shell when the error happens? Hopefully it can at least serve as a workaround until I figure out what's going on.

    Can you try adding setopt xtrace at the top of ~/.zshrc and invoke unsetopt xtrace after z4h init? Like this:

    diff --git a/.zshrc b/.zshrc
    index 54480ae..5ae5b94 100644
    --- a/.zshrc
    +++ b/.zshrc
    @@ -1,3 +1,5 @@
    +setopt xtrace
    +
     # Personal Zsh configuration file. It is strongly recommended to keep all
     # shell customization and configuration (including exported environment
     # variables such as PATH) in this file or in files source by it.
    @@ -50,7 +52,11 @@ z4h install ohmyzsh/ohmyzsh || return
     # initialize Zsh. After this point console I/O is unavailable until Zsh
     # is fully initialized. Everything that requires user interaction or can
     # perform network I/O must be done above. Everything else is best done below.
    -z4h init || return
    +{
    +  z4h init || return
    +} always {
    +  unsetopt xtrace
    +}
     
     # Extend PATH.
     path=(~/bin $path)

    With this change your terminal will produce a lot of output when you start it. If you can catch the bug with it, please post as much of the output from the end as you can.

  2. shah commented on Nov 22, 2021

    @shah
    Author

    Thanks for the quick reply, @romkatv - yes, running exec zsh does fix it (as does z4h update). I will do the tracing you mentioned above and get back to you with what I discover. Perhaps my pain can help others! :-)

  3. shah commented on Nov 22, 2021

    @shah
    Author

    @romkatv here's what I see when I turn on xtrace as you suggested:

    +/home/snshah/.zshrc:11> zstyle :z4h: auto-update no
    +/home/snshah/.zshrc:13> zstyle :z4h: auto-update-days 28
    +/home/snshah/.zshrc:16> zstyle :z4h: prompt-at-bottom yes
    +/home/snshah/.zshrc:19> zstyle :z4h:bindkey keyboard pc
    +/home/snshah/.zshrc:23> zstyle :z4h:autosuggestions forward-char accept
    +/home/snshah/.zshrc:26> zstyle :z4h:fzf-complete recurse-dirs no
    +/home/snshah/.zshrc:29> zstyle :z4h:direnv enable yes
    +/home/snshah/.zshrc:31> zstyle :z4h:direnv:success notify yes
    +/home/snshah/.zshrc:35> zstyle :z4h:ssh:example-hostname1 enable yes
    +/home/snshah/.zshrc:36> zstyle ':z4h:ssh:*.example-hostname2' enable no
    +/home/snshah/.zshrc:38> zstyle ':z4h:ssh:*' enable no
    +/home/snshah/.zshrc:42> zstyle ':z4h:ssh:*' send-extra-files '~/.nanorc' '~/.env.zsh'
    +/home/snshah/.zshrc:45> zstyle :z4h:ssh-agent: start yes
    +/home/snshah/.zshrc:52> z4h install ohmyzsh/ohmyzsh
    +z4h:1> ((  1  ))
    +z4h:2> -z4h-cmd-install ohmyzsh/ohmyzsh
    +-z4h-cmd-install:1> eval $'emulate -L zsh &&\n  setopt typeset_silent pipe_fail extended_glob prompt_percent no_prompt_subst &&\n  setopt no_prompt_bang no_bg_nice no_aliases'
    +(eval):1> emulate -L zsh
    +(eval):2> setopt typeset_silent pipe_fail extended_glob prompt_percent no_prompt_subst
    +(eval):3> setopt no_prompt_bang no_bg_nice no_aliases
    +-z4h-cmd-install:2> -z4h-check-core-params
    +-z4h-check-core-params:1> [[ $'ZDOTDIR=/home/snshah\C-@Z4H=/home/snshah/.cache/zsh4humans/v5\C-@Z4H_URL=https://raw.githubusercontent.com/romkatv/zsh4humans/v5' == ZDOTDIR=/home/snshahZ4H=/home/snshah/.cache/zsh4humans/v5Z4H_URL=https://raw.githubusercontent.com/romkatv/zsh4humans/v5 ]]
    +-z4h-cmd-install:4> local -a flush
    +-z4h-cmd-install:5> zparseopts -D -F -- 'f=flush' '-flush=flush'
    +-z4h-cmd-install:7> local invalid=( )
    +-z4h-cmd-install:8> ((  0  ))
    +-z4h-cmd-install:14> _z4h_install_queue+=( ohmyzsh/ohmyzsh )
    +-z4h-cmd-install:15> ((  0 && 1  ))
    +-z4h-cmd-install:15> return 0
    +/home/snshah/.zshrc:59> z4h init
    +z4h:1> ((  1  ))
    +z4h:2> -z4h-cmd-init
    +-z4h-cmd-init:1> ((  ARGC  ))
    +-z4h-cmd-init:5> ((  0  ))
    +-z4h-cmd-init:17> -z4h-check-core-params
    +-z4h-check-core-params:1> [[ $'ZDOTDIR=/home/snshah\C-@Z4H=/home/snshah/.cache/zsh4humans/v5\C-@Z4H_URL=https://raw.githubusercontent.com/romkatv/zsh4humans/v5' == ZDOTDIR=/home/snshahZ4H=/home/snshah/.cache/zsh4humans/v5Z4H_URL=https://raw.githubusercontent.com/romkatv/zsh4humans/v5 ]]
    +-z4h-cmd-init:18> typeset -gri _z4h_init_called=1
    +-z4h-cmd-init:20> '(anon)'
    +(anon):1> eval $'emulate -L zsh &&\n  setopt typeset_silent pipe_fail extended_glob prompt_percent no_prompt_subst &&\n  setopt no_prompt_bang no_bg_nice no_aliases'
    +(eval):1> emulate -L zsh
    +(eval):2> setopt typeset_silent pipe_fail extended_glob prompt_percent no_prompt_subst
    +(eval):3> setopt no_prompt_bang no_bg_nice no_aliases
    +(anon):3> local -a start_tmux
    +(anon):5> zstyle -a :z4h: start-tmux start_tmux
    +(anon):5> start_tmux=( integrated )
    +(anon):6> local -i install_tmux need_restart
    +(anon):7> ((  1 == 1  ))
    +(anon):8> case integrated (integrated)
    +(anon):9> install_tmux=1
    +(anon):14> [[ _z4h_zle -eq 1 && -o zle && -t 0 && -t 1 && -t 2 ]]
    +(anon):17> [[ '' == /dev/pts/0 ]]
    +(anon):17> unset _Z4H_TMUX _Z4H_TMUX_CMD _Z4H_TMUX_TTY
    +(anon):18> local tmux=/home/snshah/.cache/zsh4humans/v5/tmux/bin/tmux
    +(anon):19> local -a match mbegin mend
    +(anon):20> [[ '' == (#b)(/*),(|<->),(|<->) ]]
    +(anon):46> ((  install_tmux  ))
    +(anon):47> [[ -z '' && ! -w '' && -z '' ]]
    +(anon):48> unset _Z4H_TMUX _Z4H_TMUX_CMD _Z4H_TMUX_TTY TMUX TMUX_PANE
    +(anon):49> [[ -x /home/snshah/.cache/zsh4humans/v5/tmux/bin/tmux && -d /home/snshah/.cache/zsh4humans/v5/terminfo ]]
    +(anon):52> local sock
    +(anon):53> [[ -n '' ]]
    +(anon):55> [[ -d /tmp && -w /tmp ]]
    +(anon):56> sock=/tmp
    +(anon):60> [[ -n /tmp ]]
    +(anon):61> [[ -e /home/snshah/.cache/zsh4humans/v5/tmux/stamp ]]
    +(anon):64> local stamp
    +(anon):65> IFS='' +(anon):65> read -r stamp
    +(anon):69> sock=/tmp/z4h-tmux-1000-xterm-256color-1637523356.6443676949
    +(anon):70> local -a cmds=( )
    +(anon):71> ((  terminfo[colors] >= 256  ))
    +(anon):72> cmds+=( set -g default-terminal tmux-256color ';' )
    +(anon):73> [[ truecolor == (24bit|truecolor) ]]
    +(anon):74> cmds+=( set -ga terminal-overrides ',*:Tc' ';' )
    +(anon):75> sock+=-tc
    +(anon):78> zstyle -t :z4h: term-vresize top
    +(anon):82> zstyle -t :z4h: propagate-cwd
    +(anon):98> local exec=exec
    +(anon):100> SHELL=/usr/local/bin/zsh _Z4H_LINES=30 _Z4H_COLUMNS=120 -/home/snshah/.cache/zsh4humans/v5/tmux/bin/tmux -u -S /tmp/z4h-tmux-1000-xterm-256color-1637523356.6443676949-tc -f /home/snshah/.cache/zsh4humans/v5/zsh4humans/.tmux.conf -- set -g default-terminal tmux-256color ';' set -ga terminal-overrides ',*:Tc' ';' new
    ^[[>0;10;1c+/home/snshah/.zshrc:11> zstyle :z4h: auto-update no
    +/home/snshah/.zshrc:13> zstyle :z4h: auto-update-days 28
    +/home/snshah/.zshrc:16> zstyle :z4h: prompt-at-bottom yes
    +/home/snshah/.zshrc:19> zstyle :z4h:bindkey keyboard pc
    +/home/snshah/.zshrc:23> zstyle :z4h:autosuggestions forward-char accept
    +/home/snshah/.zshrc:26> zstyle :z4h:fzf-complete recurse-dirs no
    +/home/snshah/.zshrc:29> zstyle :z4h:direnv enable yes
    +/home/snshah/.zshrc:31> zstyle :z4h:direnv:success notify yes
    +/home/snshah/.zshrc:35> zstyle :z4h:ssh:example-hostname1 enable yes
    +/home/snshah/.zshrc:36> zstyle ':z4h:ssh:*.example-hostname2' enable no
    +/home/snshah/.zshrc:38> zstyle ':z4h:ssh:*' enable no
    +/home/snshah/.zshrc:42> zstyle ':z4h:ssh:*' send-extra-files '~/.nanorc' '~/.env.zsh'
    +/home/snshah/.zshrc:45> zstyle :z4h:ssh-agent: start yes
    +/home/snshah/.zshrc:52> z4h install ohmyzsh/ohmyzsh
    +z4h:1> ((  1  ))
    +z4h:2> -z4h-cmd-install ohmyzsh/ohmyzsh
    +-z4h-cmd-install:1> eval $'emulate -L zsh &&\n  setopt typeset_silent pipe_fail extended_glob prompt_percent no_prompt_subst &&\n  setopt no_prompt_bang no_bg_nice no_aliases'
    +(eval):1> emulate -L zsh
    +(eval):2> setopt typeset_silent pipe_fail extended_glob prompt_percent no_prompt_subst
    +(eval):3> setopt no_prompt_bang no_bg_nice no_aliases
    +-z4h-cmd-install:2> -z4h-check-core-params
    +-z4h-check-core-params:1> [[ $'ZDOTDIR=/home/snshah\C-@Z4H=/home/snshah/.cache/zsh4humans/v5\C-@Z4H_URL=https://raw.githubusercontent.com/romkatv/zsh4humans/v5' == ZDOTDIR=/home/snshahZ4H=/home/snshah/.cache/zsh4humans/v5Z4H_URL=https://raw.githubusercontent.com/romkatv/zsh4humans/v5 ]]
    +-z4h-cmd-install:4> local -a flush
    +-z4h-cmd-install:5> zparseopts -D -F -- 'f=flush' '-flush=flush'
    +-z4h-cmd-install:7> local invalid=( )
    +-z4h-cmd-install:8> ((  0  ))
    +-z4h-cmd-install:14> _z4h_install_queue+=( ohmyzsh/ohmyzsh )
    +-z4h-cmd-install:15> ((  0 && 1  ))
    +-z4h-cmd-install:15> return 0
    +/home/snshah/.zshrc:59> z4h init
    +z4h:1> ((  1  ))
    +z4h:2> -z4h-cmd-init
    +-z4h-cmd-init:1> ((  ARGC  ))
    +-z4h-cmd-init:5> ((  0  ))
    +-z4h-cmd-init:17> -z4h-check-core-params
    +-z4h-check-core-params:1> [[ $'ZDOTDIR=/home/snshah\C-@Z4H=/home/snshah/.cache/zsh4humans/v5\C-@Z4H_URL=https://raw.githubusercontent.com/romkatv/zsh4humans/v5' == ZDOTDIR=/home/snshahZ4H=/home/snshah/.cache/zsh4humans/v5Z4H_URL=https://raw.githubusercontent.com/romkatv/zsh4humans/v5 ]]
    +-z4h-cmd-init:18> typeset -gri _z4h_init_called=1
    +-z4h-cmd-init:20> '(anon)'
    +(anon):1> eval $'emulate -L zsh &&\n  setopt typeset_silent pipe_fail extended_glob prompt_percent no_prompt_subst &&\n  setopt no_prompt_bang no_bg_nice no_aliases'
    +(eval):1> emulate -L zsh
    +(eval):2> setopt typeset_silent pipe_fail extended_glob prompt_percent no_prompt_subst
    +(eval):3> setopt no_prompt_bang no_bg_nice no_aliases
    +(anon):3> local -a start_tmux
    +(anon):5> zstyle -a :z4h: start-tmux start_tmux
    +(anon):5> start_tmux=( integrated )
    +(anon):6> local -i install_tmux need_restart
    +(anon):7> ((  1 == 1  ))
    +(anon):8> case integrated (integrated)
    +(anon):9> install_tmux=1
    +(anon):14> [[ _z4h_zle -eq 1 && -o zle && -t 0 && -t 1 && -t 2 ]]
    +(anon):17> [[ '' == /dev/pts/3 ]]
    +(anon):17> unset _Z4H_TMUX _Z4H_TMUX_CMD _Z4H_TMUX_TTY
    +(anon):18> local tmux=/home/snshah/.cache/zsh4humans/v5/tmux/bin/tmux
    +(anon):19> local -a match mbegin mend
    +(anon):20> [[ /tmp/z4h-tmux-1000-xterm-256color-1637523356.6443676949-tc,1590,0 == (#b)(/*),(|<->),(|<->) && -w /tmp/z4h-tmux-1000-xterm-256color-1637523356.6443676949-tc ]]
    +(anon):21> [[ /tmp/z4h-tmux-1000-xterm-256color-1637523356.6443676949-tc,1590,0 == */z4h-tmux-* ]]
    +(anon):22> export _Z4H_TMUX=/tmp/z4h-tmux-1000-xterm-256color-1637523356.6443676949-tc,1590,0
    +(anon):23> export _Z4H_TMUX_PANE=%0
    +(anon):24> export _Z4H_TMUX_CMD=/home/snshah/.cache/zsh4humans/v5/tmux/bin/tmux
    +(anon):25> export _Z4H_TMUX_TTY=/dev/pts/3
    +(anon):26> unset TMUX TMUX_PANE
    +(anon):38> [[ -n /tmp/z4h-tmux-1000-xterm-256color-1637523356.6443676949-tc,1590,0 && -t 1 ]]
    +(anon):39> zstyle -T :z4h: prompt-at-bottom
    +(anon):40> zselect -t0 -r 0
    +(anon):41> local cursor_y cursor_x
    +(anon):42> -z4h-get-cursor-pos
    +-z4h-get-cursor-pos:3> local esc
    +-z4h-get-cursor-pos:4> IFS='[;' +-z4h-get-cursor-pos:4> read -s -d R $'esc?\C-[[6n' cursor_y cursor_x
    (anon):43: bad math expression: operand expected at `>0'
    +/home/snshah/.zshrc:61> unsetopt xtrace

    I'm using Debian 11 on WSL2 on Windows 11 on an AMD64 5700G CPU. But the same happens on other CPUs as well. Thanks for checking into this!

    When the error above occurs and I run exec zsh all is well again.
    Seems to be related to it being a login shell vs. a regular shell.?

  4. romkatv commented on Nov 22, 2021

    @romkatv
    Owner

    Thanks for the info. It's valuable. You can turn off xtrace. I'll get back to you once I have a fix or a question. Use exec zsh as a workaround until then.

  5. romkatv commented on Nov 22, 2021

    @romkatv
    Owner

    I think I've figured out what's going on.

    Your terminal takes a very long time to reply to secondary DA request (\033[>c). After one second tmux gives up and marks the terminal as not having any features. Eventually the response to the request arrives (\033[>0;10;1c) and tmux lets it pass through to the client because it's not expending this response anymore.

    A proper fix would be to figure out why your terminal takes so long to reply and fix it. Maybe it's one of those Windows 11 things. I'll also implement a workaround in z4h so that shell doesn't break when the terminal is in a sorry state like this.

  6. romkatv commented on Nov 22, 2021

    @romkatv
    Owner

    I'll also implement a workaround in z4h so that shell doesn't break when the terminal is in a sorry state like this.

    This is done. You can pick up the fix with z4h update.

  7. shah commented on Nov 22, 2021

    @shah
    Author

    Looks great so far @romkatv!

  8. romkatv commented on Nov 22, 2021

    @romkatv
    Owner

    Thanks for verifying. Closing. I've opened an issue with the upstream: tmux/tmux#2984

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions