MichaelAquilina / zsh-you-should-use

📎 ZSH plugin that reminds you to use existing aliases for commands you just typed
GNU General Public License v3.0
1.46k stars 43 forks source link

Error : maximum nested function level reached #13

Closed JoshuaCrewe closed 7 years ago

JoshuaCrewe commented 7 years ago

zsh --version zsh 5.3.1 (x86_64-apple-darwin15.6.0)

I am using zplug to manage zsh plugins. I used zplug to install this plugin about a week ago and have had success with it. I updated all my installed plugins ( about 9 in total including this one ) and found that I got this error when trying to run any command in the terminal.

local:6: maximum nested function level reached

The number varies and the message appears at the start and end of output in the terminal.

Removed zplug, uninstalling everything and then installed each plugin one by one and narrowed the issue down to this plugin.

I can reproduce the issue by starting from scratch with a fresh install of zplug and this plugin only.

Here is the part of my .zshrc that produces the error :

# Check if zplug is installed
if [[ ! -d ~/.zplug ]]; then
    curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh| zsh
fi

source ~/.zplug/init.zsh

# zplug "zplug/zplug"                                # Have zplug manage its self
# zplug "zsh-users/zsh-syntax-highlighting", defer:2 # Use colour to show acutal commands
# zplug "urbainvaes/fzf-marks"                       # Bookmarking with fzf filtering
#
# zplug "b4b4r07/zsh-gomi"                           # Move things to system trash
# zplug "zsh-users/zsh-completions"

zplug "MichaelAquilina/zsh-you-should-use"

# zplug "mafredri/zsh-async", from:github
# zplug "sindresorhus/pure", use:pure.zsh, from:github, as:theme
#
# zplug "pimterry/notes", \
#     as:command, \
#     use:notes
#
# zplug "paulirish/git-open"
# #
# zplug "witt3rd/894c9e0b9ca4e24e5574", \
#     from:gist, \
#     as:command, \
#     use:brew-sync.sh                               # Keep homebrew in sync with dropbox

Install plugins if there are plugins that have not been installed
if ! zplug check --verbose; then
    printf "Install? [y/N]: "
    if read -q; then
        echo; zplug install
    fi
fi

# Then, source plugins and add commands to $PATH
zplug load --verbose

Happy to clarify anything that I have not made clear, happy to provide any information needed to further debug the issue.

MichaelAquilina commented 7 years ago

Thank you for reporting this :) Could you provide your list of aliases with the following commands?

alias alias -g

Thanks!

MichaelAquilina commented 7 years ago

Btw at first glance I cant see any reason why this would be happening because the code does not have any recursive functions, but let's dig a bit deeper before

JoshuaCrewe commented 7 years ago

Sure. This is going to be embarrassing. alias

-='cd -'
...=../..
....=../../..
.....=../../../..
......=../../../../..
:q=exit
:wq=exit
accio=wget
alohamora='openssl enc -d -aes-256-cbc'
avadaKedavra='rm -f'
brewu='brew update && brew upgrade && brew cleanup && brew prune && brew doctor'
colloportus='openssl enc -aes-256-cbc'
ctags='ctags -R -f .tags .'
dt=dasht
engorgio=unzip
expectoPatronum='open ~/Pictures/turtleBasking.jpg'
g=git
ga='git add '
gb='git branch '
gc='git commit'
gd='git diff'
get='git '
go='git checkout '
gomi='gomi -s'
got='git '
gs='git status '
hide='defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder'
imperio=sudo
j=jump
l='ls -lah'
la='ls -lAh'
legilimens='defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder'
ll='ls -lh'
ls='ls -G'
lsa='ls -lah'
lyn=learnyounode
m=mark
note=notes
o=open
obliviate='history -c; history -w'
obscuro='/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'
occlumens='defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder'
priorIncantato='echo `history |tail -n2 |head -n1` | sed "s/[0-9]* //"'
psa='ps aux'
psg='ps aux | grep '
psgg='ps aux | grep gulp'
quietus='set +v'
reducio='zip -r'
run-help=man
show='defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder'
sonorus='set -v'
stupefy='sleep 5'
sz='source ~/.zshrc'
tergeo='defaults write com.apple.finder CreateDesktop -bool false && killall Finder'
tmux='tmux -2'
tmuxconf='vim -c e ~/dotfiles/tmux.conf'
trash='gomi -s'
untergeo='defaults write com.apple.finder CreateDesktop -bool true && killall Finder'
vimrc='vim -c e ~/dotfiles/vimrc'
which-command=whence
wingardiumLeviosa=mv
zsh-aliases='vim -c e ~/dotfiles/zsh/aliases/init.zsh'
zsh-functions='vim -c e ~/dotfiles/zsh/functions/init.zsh'
zsh-options='vim -c e ~/dotfiles/zsh/options/init.zsh'
zsh-plugins='vim -c e ~/dotfiles/zsh/plugins/init.zsh'
zshrc='vim -c e ~/dotfiles/zshrc'

alias -g

...=../..
....=../../..
.....=../../../..
......=../../../../..

Most illuminating! Harry Potter Aliases if anyone is interested

MichaelAquilina commented 7 years ago

Till now, sourcing all your aliases does not provide me with the error, so I will attempt to use your .zshrc file as a next step. Have you attempted to comment this package out too to see if you still get the error? Perhaps something is being sourced along the way that you are unaware of?

JoshuaCrewe commented 7 years ago

Yeah nice idea. I'll carry on narrowing down my config to see what's up. Given your response it is almost certainly my end.

I'll get an update tomorrow when I am back with my computer :) cheers!

MichaelAquilina commented 7 years ago

I've tried using both your zshrc file and your alias list at the same time and I still didnt experience any issues.

$ zsh --version
zsh 5.3.1 (x86_64-suse-linux-gnu)

We have the zsh version so I'm quite sure that the issue isn't actually coming from this package. I mentioned already that this plugin does not use recursive functions, so I'm 99% sure this is true.

I will keep this open for a while longer in case anyone else is experiencing this issue or if you find more information,

MichaelAquilina commented 7 years ago

btw something I noticed while using your aliases is that it reminds you of aliases despite the fact they may be longer. Is this something you would consider desired behaviour or do you think its an improvement for me to add a check that the alias is shorter than the command?

Navisence commented 7 years ago

I'm experiencing a similar issue. Read about you-should-use on Cron.weekly and tried it by downloading the zip here and extracted to .oh-my-zsh/custom/plugins/you-should-use

~ ls .oh-my-zsh/custom/plugins/you-should-use 
README.md  you-should-use.plugin.zsh

I'm using zsh on debian 8.

~ zsh --version
zsh 5.0.7 (x86_64-pc-linux-gnu)

After reading the above, I've disabled all plugins - no issue anymore. When enabling just you-should-use in .zshrc I'm also getting the maximum nested function level reached messages.

plugins=(you-should-use)

The first command still returns output (snipped below). From then on every keystroke produces a few lines like below.

~ source .zshrc
~ ls
local:6: maximum nested function level reached
<snipped ls output>
local:1: maximum nested function level reached                                  
~ 
local:2: maximum nested function level reached
local:1: maximum nested function level reached
~ 
local:1: maximum nested function level reached                                  
~ 
local:2: maximum nested function level reached
local:1: maximum nested function level reached
~ 
local:1: maximum nested function level reached                                  

Aliases:

~ alias
-='cd -'
...=../..
....=../../..
.....=../../../..
......=../../../../..
1='cd -'
2='cd -2'
3='cd -3'
4='cd -4'
5='cd -5'
6='cd -6'
7='cd -7'
8='cd -8'
9='cd -9'
_=sudo
afind='ack -il'
cp='cp -i'
d='dirs -v | head -10'
globurl='noglob urlglobber '
grep='grep  --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}'
history='fc -l 1'
l='ls -lah'
la='ls -lAh'
ll='ls -artl'
ls='ls --color=tty'
lsa='ls -lah'
md='mkdir -p'
mv='mv -i'
please=sudo
po=popd
pu=pushd
rd=rmdir
rm='rm -i'
which-command=whence
~ alias -g
...=../..
....=../../..
.....=../../../..
......=../../../../..
MichaelAquilina commented 7 years ago

Multiple users experiencing this tells me it must be a problem within this project after all. It just seems to be one of those bugs that's difficult to reproduce. I'll try think up of some things that could help me get more information or debug further.

MichaelAquilina commented 7 years ago

~@JoshuaCrewe are you also using Oh-my-zsh?~ Just remembered you posted your zshrc file already and can see it uses zplug

JoshuaCrewe commented 7 years ago

I have been trying to slim down my rc to just the bare minimum that recreates the issue. I have found that it can be just zplug and this plugin, unfortunately. I have enabled each plugin one by one and found the issue only arises when this one is enabled.

I did notice one other thing. When it was just this one plugin I got the error local:6: maximum nested function level reached but the terminal was still usable. If this plugin is installed alongside 'zsh-users/zsh-syntax-highlighting' then I get the same result as @Navisence . With every keypress the error is output.

Happy to test out anything you think @MichaelAquilina , I am no zsh expert though.

btw something I noticed while using your aliases is that it reminds you of aliases despite the fact they may be longer. Is this something you would consider desired behaviour or do you think its an improvement for me to add a check that the alias is shorter than the command?

I would say so yes. I have the HP aliases for fun. I don't use them. I noticed that when I used mv I would be prompted to use wingardiumLeviosa, which while amusing is maybe not in the spirit of this plugin :)

MichaelAquilina commented 7 years ago

@JoshuaCrewe aliases which are longer than their command are no longer suggested as of https://github.com/MichaelAquilina/zsh-you-should-use/commit/d08f4c66ebc3df5be01a784044e10711155af145.

Could you guys try running the command set -x in a terminal. This will print each line that's run to stdout.

Once its set, run something that you know was giving you that error and take the output printed. It will be very verbose but put that all in a gist and paste the link here for me to look at

JoshuaCrewe commented 7 years ago

Morning!

This was not quite what I expected from this command, but it does seem to tell us something.

gist of set -x output

I skimmed my config down to just this plug in and the aliases. There are none of my functions in there and exports etc are not included either. Loaded with zplug and no other plugins.

( In case it is not clear, I did not include all of the lines of output. That +local:6> local 'best_match=' was printed a lot! )

MichaelAquilina commented 7 years ago

This gives me an idea of where to look now at least. Thanks :)

MichaelAquilina commented 7 years ago

Can you guys both confirm that you are on the latest version of zsh-you-should-use? On zplug you can run zplug update.

MichaelAquilina commented 7 years ago

Also, could you tell me what the output of which local gives?

Navisence commented 7 years ago

This is my gist of set -x output.

The version is the zip file downloaded from here last Monday.

~ which local
local: shell built-in command
JoshuaCrewe commented 7 years ago

It is the latest version which zplug can give me. I have been uninstalling and reinstalling it to do these tests so I am pretty sure it is getting the latest one.

Joshua% which local
local:6: maximum nested function level reached
local () {
        local best_match=""
}
MichaelAquilina commented 7 years ago

It's quite odd because it seems to keep repeating the first line of the function - which is just declaring a variable. I suspect there is something else in your environment which is treating that line as a recursive function.

Could you tell me what the output of the following commands are?

$ echo $preexec_functions
$ echo $precmd_functions
$ echo $chpwd_functions
MichaelAquilina commented 7 years ago

@JoshuaCrewe @Navisence could you try running #20 and see if the error still persists?

JoshuaCrewe commented 7 years ago
$ echo $preexec_functions
_check_aliases _check_global_aliases _check_git_aliases

$ echo $precmd_functions

$ echo $chpwd_functions

The last two were blank.

I have changed branch in the repo to origin/hotfix_attempt_1 and I get a new error :

_check_global_aliases:3: bad pattern: tokens=(......
[1]    done        |

The original error is no more though.

JoshuaCrewe commented 7 years ago

I do get the intended functionality for the plug in though. i.e it will print out a better alias to use instead of the command I types.

MichaelAquilina commented 7 years ago

ah! That is a different error from a different function. Interesting that it fails for you but runs for me, must be something subtley different about our zsh versions

MichaelAquilina commented 7 years ago

Just pushed a new change. Could you try it out?

JoshuaCrewe commented 7 years ago

That's progress though! Are we not running the same version of zsh then ?

MichaelAquilina commented 7 years ago

From the looks of it, we should be. But the fact you get a syntax error when I dont is very strange and is usually something you expect out of different zsh versions. Did the new change that was pushed fix the new error?

JoshuaCrewe commented 7 years ago

That was confusing, zplug kept switching back to master.

I get :

$ gs
_check_git_aliases:4: bad pattern: tokens=(alias.a

similar but not the same.

MichaelAquilina commented 7 years ago

Its strange that that's the entire line :/ What happens if you run _check_global_aliases "git status" "git status" (with set -x still on)

MichaelAquilina commented 7 years ago

Oh wait I just realised thats another error. I wonder why your version of zsh is more strict about this

MichaelAquilina commented 7 years ago

Alright @JoshuaCrewe this should fix all your errors now. Try it out

JoshuaCrewe commented 7 years ago

🎉🎉🎉

That seems to have done it. Nice work! So zsh doesn't always like defining a variable and setting it at the same time ? For some reason my zsh doesn't like it more than yours ...

Presumably it is the same for @Navisence too ?

MichaelAquilina commented 7 years ago

I am still unsure why this is the case. It might be differences in how zsh is compiled. If you want to be adventurous, try downloading the zsh source code, compiling it and seeing if the issue still arises for you without my fixes :)

MichaelAquilina commented 7 years ago

Will wait for @Navisence that this fix works for him too. Once I get confirmation I will merge a new release into master and you guys can change back to master after updating

JoshuaCrewe commented 7 years ago

Well that's certainly one way to spend an afternoon!

MichaelAquilina commented 7 years ago

@JoshuaCrewe @Navisence the fixes have been merged into master. Give it a go and let me know whether we can close this issue

Navisence commented 7 years ago

Just tested the master and your fixes resolve the issue for me. Thanks!

MichaelAquilina commented 7 years ago

Great to hear!

JoshuaCrewe commented 7 years ago

Good stuff. No issues here neither.