Closed srijanshetty closed 9 years ago
What problem are you seeing?
We're using typeset -A
, so the link to zsh-workers appears to be irrelevant, isn't it?
@blueyed : I used to get _autoenv_stack_entered_remove:4 bad math expression : at operand '/home..' _autoenv_stack_entered_add:10 bad math expression : at operand '/home..'
Both of these seem fixed now :smile:
Cool! If you know what fixed it, let us know. :)
@srijanshetty
Please try it with export AUTOENV_DEBUG=2
.
The error comes from here:
_autoenv_stack_entered_mtime[$env_file]=
(https://github.com/Tarrasch/zsh-autoenv/blob/master/autoenv.zsh#L75)
Please also try adding set -x
to the beginning of _autoenv_stack_entered_remove
, and set +x
at the end.
This is the trace when I used the set +x route.
Yes, I strongly believe that the error orginates from
_autoenv_stack_entered_mtime[$env_file]=
On commenting the same, the errors vanish.
Please post the output of setopt
.
And the output from zsh --version
.
With export AUTOENV_DEBUG=2
:
$ cd projects/myproject
[autoenv] Calling chpwd handler: PWD=/home/ryne/projects/myproject
[autoenv] [stack] adding: /home/ryne/projects/myproject/.env
[autoenv] [stack] removing: /home/ryne/projects/myproject/.env
_autoenv_stack_entered_remove:4: bad math expression: operand expected at `/home/ryne...'
$ setopt
interactive
monitor
promptsubst
shinstdin
zle
$ zsh --version
zsh 5.0.7 (x86_64-unknown-linux-gnu)
This commit appears to be the culprit.
This commit appears to be the culprit.
That commit added the functionality, yes.
Your zsh version is recent, which is good.
Have you removed the noclobber
option again? (otherwise it should have shown up in setopt
's output).
Can you please try running make test
and make test_full
(if the former did not fail already)?
You are not changing the _autoenv_stack_entered_remove
var somewhere, do you?
Please provide the contents of /home/ryne/projects/myproject/.env
, and the output from set|cat -A|grep -i autoenv
.
It boils down to some weirdness with associative arrays.
Please also try the following in an interactive shell. Does it work?
typeset -A a
s=/home/ryne/projects/myproject/.env
a[$s]=
a[$s]=""
a[$s]=foo
I don't think I've ever set the noclobber
option. (Maybe I should though.) I've also never modified _autoenv_stack_entered_remove
to my knowledge. I have a very minimal setup.
$ make test
cram --shell=zsh -v tests
tests/_autoenv_stack.t: passed
tests/_autoenv_utils.t: passed
tests/autoenv.t: passed
tests/cwd.t: passed
tests/leave.t: passed
tests/recurse-upwards.t: passed
tests/varstash.t: passed
# Ran 7 tests, 0 skipped, 0 failed.
$ make test_full
for i in tests/ZDOTDIR.clobber tests/ZDOTDIR; do \
echo "ZDOTDIR=$i"; \
ZDOTDIR=/home/ryne/projects/zsh-autoenv/$i cram --shell=zsh -v tests; \
done
ZDOTDIR=tests/ZDOTDIR.clobber
tests/_autoenv_stack.t: passed
tests/_autoenv_utils.t: passed
tests/autoenv.t: passed
tests/cwd.t: passed
tests/leave.t: passed
tests/recurse-upwards.t: passed
tests/varstash.t: passed
# Ran 7 tests, 0 skipped, 0 failed.
ZDOTDIR=tests/ZDOTDIR
tests/_autoenv_stack.t: passed
tests/_autoenv_utils.t: passed
tests/autoenv.t: passed
tests/cwd.t: passed
tests/leave.t: passed
tests/recurse-upwards.t: passed
tests/varstash.t: passed
# Ran 7 tests, 0 skipped, 0 failed.
$ set|cat -A|grep -i autoenv
AUTOENV_DEBUG=2$
AUTOENV_ENV_FILENAME=/home/ryne/.env_auth$
AUTOENV_FILE_ENTER=.env$
AUTOENV_FILE_LEAVE=.env.leave$
AUTOENV_HANDLE_LEAVE=1$
AUTOENV_LOOK_UPWARDS=1$
FPATH=/home/ryne/.antigen/repos/https-COLON--SLASH--SLASH-github.com-SLASH-Tarrasch-SLASH-zsh-autoenv.git//:/usr/local/share/zsh/site-functions:/usr/share/zsh/site-functions:/usr/share/zsh/functions/Calendar:/usr/share/zsh/functions/Chpwd:/usr/share/zsh/functions/Completion:/usr/share/zsh/functions/Completion/Base:/usr/share/zsh/functions/Completion/Linux:/usr/share/zsh/functions/Completion/Unix:/usr/share/zsh/functions/Completion/X:/usr/share/zsh/functions/Completion/Zsh:/usr/share/zsh/functions/Exceptions:/usr/share/zsh/functions/MIME:/usr/share/zsh/functions/Misc:/usr/share/zsh/functions/Newuser:/usr/share/zsh/functions/Prompts:/usr/share/zsh/functions/TCP:/usr/share/zsh/functions/VCS_Info:/usr/share/zsh/functions/VCS_Info/Backends:/usr/share/zsh/functions/Zftp:/usr/share/zsh/functions/Zle$
_ANTIGEN_BUNDLE_RECORD='\nhttps://github.com/Tarrasch/zsh-autoenv.git / plugin true'$
_autoenv_chpwd_prev_dir=/home/ryne$
_autoenv_source_dir=/home/ryne/.antigen/repos/https-COLON--SLASH--SLASH-github.com-SLASH-Tarrasch-SLASH-zsh-autoenv.git$
_autoenv_stack_entered=()$
_autoenv_stack_entered_mtime=()$
chpwd_functions=(_autoenv_chpwd_handler)$
fpath=(/home/ryne/.antigen/repos/https-COLON--SLASH--SLASH-github.com-SLASH-Tarrasch-SLASH-zsh-autoenv.git// /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/functions/Calendar /usr/share/zsh/functions/Chpwd /usr/share/zsh/functions/Completion /usr/share/zsh/functions/Completion/Base /usr/share/zsh/functions/Completion/Linux /usr/share/zsh/functions/Completion/Unix /usr/share/zsh/functions/Completion/X /usr/share/zsh/functions/Completion/Zsh /usr/share/zsh/functions/Exceptions /usr/share/zsh/functions/MIME /usr/share/zsh/functions/Misc /usr/share/zsh/functions/Newuser /usr/share/zsh/functions/Prompts /usr/share/zsh/functions/TCP /usr/share/zsh/functions/VCS_Info /usr/share/zsh/functions/VCS_Info/Backends /usr/share/zsh/functions/Zftp /usr/share/zsh/functions/Zle)$
My .env
file contains:
echo "foobar"
As for those last commands, I'm not exactly sure what I'm supposed to be looking for. After running them all:
$ echo $a
foo
Wasn't #15 about using "noclobber", or did you just notice that it could fail?
As for those last commands, I'm not exactly sure what I'm supposed to be looking for. After running them all:
That was basically code that gets used also in autoenv, and I would have expected it to fail with some error, too.
Please provide the output of set|cat -A|grep -i autoenv
before and after you triggered the error.
I know nothing about #15, I'm just a random internet person. :) This is my first day trying this plugin...did you think I was the OP of this issue?
At any rate, that code gave no error.
$ set|cat -A|grep -i autoenv
AUTOENV_DEBUG=2$
AUTOENV_ENV_FILENAME=/home/ryne/.env_auth$
AUTOENV_FILE_ENTER=.env$
AUTOENV_FILE_LEAVE=.env.leave$
AUTOENV_HANDLE_LEAVE=1$
AUTOENV_LOOK_UPWARDS=1$
FPATH=/home/ryne/.antigen/repos/https-COLON--SLASH--SLASH-github.com-SLASH-Tarrasch-SLASH-zsh-autoenv.git//:/usr/local/share/zsh/site-functions:/usr/share/zsh/site-functions:/usr/share/zsh/functions/Calendar:/usr/share/zsh/functions/Chpwd:/usr/share/zsh/functions/Completion:/usr/share/zsh/functions/Completion/Base:/usr/share/zsh/functions/Completion/Linux:/usr/share/zsh/functions/Completion/Unix:/usr/share/zsh/functions/Completion/X:/usr/share/zsh/functions/Completion/Zsh:/usr/share/zsh/functions/Exceptions:/usr/share/zsh/functions/MIME:/usr/share/zsh/functions/Misc:/usr/share/zsh/functions/Newuser:/usr/share/zsh/functions/Prompts:/usr/share/zsh/functions/TCP:/usr/share/zsh/functions/VCS_Info:/usr/share/zsh/functions/VCS_Info/Backends:/usr/share/zsh/functions/Zftp:/usr/share/zsh/functions/Zle$
_ANTIGEN_BUNDLE_RECORD='\nhttps://github.com/Tarrasch/zsh-autoenv.git / plugin true'$
_autoenv_chpwd_prev_dir=/home/ryne$
_autoenv_source_dir=/home/ryne/.antigen/repos/https-COLON--SLASH--SLASH-github.com-SLASH-Tarrasch-SLASH-zsh-autoenv.git$
chpwd_functions=(_autoenv_chpwd_handler)$
fpath=(/home/ryne/.antigen/repos/https-COLON--SLASH--SLASH-github.com-SLASH-Tarrasch-SLASH-zsh-autoenv.git// /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/functions/Calendar /usr/share/zsh/functions/Chpwd /usr/share/zsh/functions/Completion /usr/share/zsh/functions/Completion/Base /usr/share/zsh/functions/Completion/Linux /usr/share/zsh/functions/Completion/Unix /usr/share/zsh/functions/Completion/X /usr/share/zsh/functions/Completion/Zsh /usr/share/zsh/functions/Exceptions /usr/share/zsh/functions/MIME /usr/share/zsh/functions/Misc /usr/share/zsh/functions/Newuser /usr/share/zsh/functions/Prompts /usr/share/zsh/functions/TCP /usr/share/zsh/functions/VCS_Info /usr/share/zsh/functions/VCS_Info/Backends /usr/share/zsh/functions/Zftp /usr/share/zsh/functions/Zle)$
$ cd projects/myproject
[autoenv] Calling chpwd handler: PWD=/home/ryne/projects/myproject
[autoenv] [stack] adding: /home/ryne/projects/myproject/.env
[autoenv] [stack] removing: /home/ryne/projects/myproject/.env
_autoenv_stack_entered_remove:4: bad math expression: operand expected at `/home/ryne...'
$ set|cat -A|grep -i autoenv
AUTOENV_DEBUG=2$
AUTOENV_ENV_FILENAME=/home/ryne/.env_auth$
AUTOENV_FILE_ENTER=.env$
AUTOENV_FILE_LEAVE=.env.leave$
AUTOENV_HANDLE_LEAVE=1$
AUTOENV_LOOK_UPWARDS=1$
FPATH=/home/ryne/.antigen/repos/https-COLON--SLASH--SLASH-github.com-SLASH-Tarrasch-SLASH-zsh-autoenv.git//:/usr/local/share/zsh/site-functions:/usr/share/zsh/site-functions:/usr/share/zsh/functions/Calendar:/usr/share/zsh/functions/Chpwd:/usr/share/zsh/functions/Completion:/usr/share/zsh/functions/Completion/Base:/usr/share/zsh/functions/Completion/Linux:/usr/share/zsh/functions/Completion/Unix:/usr/share/zsh/functions/Completion/X:/usr/share/zsh/functions/Completion/Zsh:/usr/share/zsh/functions/Exceptions:/usr/share/zsh/functions/MIME:/usr/share/zsh/functions/Misc:/usr/share/zsh/functions/Newuser:/usr/share/zsh/functions/Prompts:/usr/share/zsh/functions/TCP:/usr/share/zsh/functions/VCS_Info:/usr/share/zsh/functions/VCS_Info/Backends:/usr/share/zsh/functions/Zftp:/usr/share/zsh/functions/Zle$
_ANTIGEN_BUNDLE_RECORD='\nhttps://github.com/Tarrasch/zsh-autoenv.git / plugin true'$
_autoenv_chpwd_prev_dir=/home/ryne$
_autoenv_source_dir=/home/ryne/.antigen/repos/https-COLON--SLASH--SLASH-github.com-SLASH-Tarrasch-SLASH-zsh-autoenv.git$
_autoenv_stack_entered=()$
_autoenv_stack_entered_mtime=()$
chpwd_functions=(_autoenv_chpwd_handler)$
fpath=(/home/ryne/.antigen/repos/https-COLON--SLASH--SLASH-github.com-SLASH-Tarrasch-SLASH-zsh-autoenv.git// /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/functions/Calendar /usr/share/zsh/functions/Chpwd /usr/share/zsh/functions/Completion /usr/share/zsh/functions/Completion/Base /usr/share/zsh/functions/Completion/Linux /usr/share/zsh/functions/Completion/Unix /usr/share/zsh/functions/Completion/X /usr/share/zsh/functions/Completion/Zsh /usr/share/zsh/functions/Exceptions /usr/share/zsh/functions/MIME /usr/share/zsh/functions/Misc /usr/share/zsh/functions/Newuser /usr/share/zsh/functions/Prompts /usr/share/zsh/functions/TCP /usr/share/zsh/functions/VCS_Info /usr/share/zsh/functions/VCS_Info/Backends /usr/share/zsh/functions/Zftp /usr/share/zsh/functions/Zle)$
did you think I was the OP of this issue?
Indeed, sorry. And thanks for helping out! But that means there are at least two people already with this strange error then..
I could think we could use a workaround without associative arrays, but I would really like to know what's causing this anyway.
Please post the output from cd ~ ; set -x ; cd projects/myproject ; set +x
.
I've committed something that might fix it at 53da60d, please test it with this one afterwards.
Somehow the associative
attribute of the var gets lost for you:
~ % typeset -A foo; foo[/foo/bar]=as
~ % typeset -a foo; foo[/foo/bar]=as
zsh: bad math expression: operand expected at `/foo/bar'
No problem.
cd ~ ; set -x ; cd projects/myproject ; set +x
[autoenv] Calling chpwd handler: PWD=/home/ryne
+/usr/bin/zsh:1> cd projects/myproject
+_autoenv_chpwd_handler:1> local 'env_file=/home/ryne/projects/myproject/.env'
+_autoenv_chpwd_handler:3> _autoenv_debug 'Calling chpwd handler: PWD=/home/ryne/projects/myproject'
+_autoenv_debug:1> local 'msg=Calling chpwd handler: PWD=/home/ryne/projects/myproject'
+_autoenv_debug:2> local 'level=1'
+_autoenv_debug:3> [[ 2 -lt 1 ]]
+_autoenv_debug:7> [[ -z '' ]]
+_autoenv_debug:8> autoload colors
+_autoenv_debug:9> colors
…
+_autoenv_debug:12> local 'indent='
+_autoenv_debug:13> [[ '' -gt 0 ]]
+_autoenv_debug:20> lines=( 'Calling chpwd handler: PWD=/home/ryne/projects/myproject' )
+_autoenv_debug:21> line=Calling chpwd handler: PWD=/home/ryne/projects/myproject
+_autoenv_debug:22> echo -n '[autoenv] '
[autoenv] +_autoenv_debug:23> echo 'Calling chpwd handler: PWD=/home/ryne/projects/myproject'
Calling chpwd handler: PWD=/home/ryne/projects/myproject
+_autoenv_chpwd_handler:6> [[ 1 == 1 ]]
+_autoenv_chpwd_handler:6> (( 0 ))
+_autoenv_chpwd_handler:24> [[ -f /home/ryne/projects/myproject/.env ]]
+_autoenv_chpwd_handler:34> _autoenv_stack_entered_contains /home/ryne/projects/myproject/.env
+_autoenv_stack_entered_contains:1> local 'env_file=/home/ryne/projects/myproject/.env'
+_autoenv_stack_entered_contains:2> (( 0 ))
+_autoenv_stack_entered_contains:9> return 1
+_autoenv_chpwd_handler:40> _autoenv_check_authorized_env_file /home/ryne/projects/myproject/.env
+_autoenv_check_authorized_env_file:1> [[ -f /home/ryne/projects/myproject/.env ]]
+_autoenv_check_authorized_env_file:4> _autoenv_authorized_env_file /home/ryne/projects/myproject/.env
+_autoenv_authorized_env_file:1> local 'env_file=/home/ryne/projects/myproject/.env'
+_autoenv_authorized_env_file:2> _autoenv_hash_pair /home/ryne/projects/myproject/.env
+_autoenv_hash_pair:1> local 'env_file=/home/ryne/projects/myproject/.env'
+_autoenv_hash_pair:2> local 'env_shasum='
+_autoenv_hash_pair:3> [[ -z '' ]]
+_autoenv_hash_pair:4> [[ -e /home/ryne/projects/myproject/.env ]]
+_autoenv_hash_pair:8> env_shasum=+_autoenv_hash_pair:8> shasum /home/ryne/projects/myproject/.env
+_autoenv_hash_pair:8> env_shasum=+_autoenv_hash_pair:8> cut '-d ' -f1
+_autoenv_hash_pair:8> env_shasum=92e07ce261081d0f84bb8fac2537c81b8e7789bb
+_autoenv_hash_pair:10> echo :/home/ryne/projects/myproject/.env:92e07ce261081d0f84bb8fac2537c81b8e7789bb:1
+_autoenv_authorized_env_file:2> local 'pair=:/home/ryne/projects/myproject/.env:92e07ce261081d0f84bb8fac2537c81b8e7789bb:1'
+_autoenv_authorized_env_file:3> test -f /home/ryne/.env_auth
+_autoenv_authorized_env_file:4> grep -qF :/home/ryne/projects/myproject/.env:92e07ce261081d0f84bb8fac2537c81b8e7789bb:1 /home/ryne/.env_auth
+_autoenv_check_authorized_env_file:22> return 0
+_autoenv_chpwd_handler:45> _autoenv_stack_entered_add /home/ryne/projects/myproject/.env
+_autoenv_stack_entered_add:1> local 'env_file=/home/ryne/projects/myproject/.env'
+_autoenv_stack_entered_add:3> _autoenv_debug '[stack] adding: /home/ryne/projects/myproject/.env' 2
+_autoenv_debug:1> local 'msg=[stack] adding: /home/ryne/projects/myproject/.env'
+_autoenv_debug:2> local 'level=2'
+_autoenv_debug:3> [[ 2 -lt 2 ]]
+_autoenv_debug:7> [[ -z '' ]]
+_autoenv_debug:8> autoload colors
…
+_autoenv_debug:12> local 'indent='
+_autoenv_debug:13> [[ '' -gt 0 ]]
+_autoenv_debug:20> lines=( '[stack] removing: /home/ryne/projects/myproject/.env' )
+_autoenv_debug:21> line=[stack] removing: /home/ryne/projects/myproject/.env
+_autoenv_debug:22> echo -n '[autoenv] '
[autoenv] +_autoenv_debug:23> echo '[stack] removing: /home/ryne/projects/myproject/.env'
[stack] removing: /home/ryne/projects/myproject/.env
+_autoenv_stack_entered_remove:3> _autoenv_stack_entered[$_autoenv_stack_entered[(i)$env_file]]=( )
+_autoenv_stack_entered_remove:4> _autoenv_stack_entered_mtime[$env_file]='' _autoenv_stack_entered_remove:4: bad math expression: operand expected at `/home/ryne...'
Still not working with the latest commits, but a slightly different output (no adding
line):
$ cd projects/myproject
[autoenv] Calling chpwd handler: PWD=/home/ryne/projects/myproject
[autoenv] [stack] removing: /home/ryne/projects/myproject/.env
_autoenv_stack_entered_remove:4: bad math expression: operand expected at `/home/ryne...'
Hehe, I came to think of my other zsh plugin: https://github.com/Tarrasch/zsh-colors
Still not working with the latest commits, but a slightly different output (no adding line):
I've fixed the order of the debug output there, not relevant.
Does cd
'ing to an env-enabled dir work after sourcing autoenv.zsh
again, i.e.:
source path/to/autoenv.zsh
cd /home/ryne/projects/myproject/.env
yes, that worked.
Ok, at last we are on to something :)
How do you setup autoenv / where do you source initially? Maybe something later causes this issue. Can you try sourcing it from .zshenv vs. .zshrc etc, please?
Please tell me how you source / use / setup autoenv.
Also @srijanshetty: you initially said it was fixed for. Was it?
I am using this at the end of my ~/.zshrc:
AUTOENV_FILE_LEAVE=.env
source ~/.dotfiles/lib/zsh-autoenv/autoenv.zsh
@blueyed : I thought that it was fixed, only to realize that I was still using my dirty fix version. When I spawned a new zsh session, the error crept up again.
@srijanshetty I see. How have you installed it? Where do you source it from? Also, does the workaround of manually sourcing it again fixes it for you, too? (see https://github.com/Tarrasch/zsh-autoenv/issues/14#issuecomment-66376293).
@blueyed : I'm using @Tarrasch's antigen-hs. I'll try out a manual source and let you know.
@blueyed : Yes the workaround of manually sourcing it fixes it for me too. (Extremely strange, might I add :open_mouth:
Could it be due to the order of where you source stuff?
I've just installed antigen, and can reproduce it, after antigen-bundle Tarrasch/zsh-autoenv
.
It's maybe because antigen activates it from a function or something similar - I'll investigate.
@Tarrasch Are you using it via antigen yourself?
Thanks @blueyed! FYI, I use the same sourcing strategy in antigen-hs as antigen. So I'm excited to hear from your investigation. :)
The typeset -A
gets lost, because it's done in a local scope (antigen's function).
Adding -g
helps here.
That was a nasty issue, with a trivial fix in the end.
Thanks for helping to get this fixed everybody! :octocat:
@blueyed : Yay! By the by, thanks for tolerating the vague error reports :smile:
@srijanshetty Did you use antigen or antigen-hs? Huge thanks for reporting this bug btw!
@blueyed What do you think would be the right behavior from a zsh plugin manager? I can easily change antigen-hs to source everything from global source, and it could save people some misery (unfortunately most people still use original antigen).
@Tarrasch Yes, sourcing from the global scope would be better I suppose.
@Tarrasch : I use antigen-hs. I like to keep it simple :smile:
The relative simplicity of manually pulling updates for individual plugins may be disputable. :)
@ryneeverett : I've wrapper functions for updating, listing, removing and adding bundles; but considering how ugly they are, I've decided not to send a PR. @Tarrasch suggested an implementation of the idea in Haskell rather than zsh, which sounds great provided I get time. P.S: You could check out my wrapper functions at https://github.com/srijanshetty/antigen-hs, but be fore warned that they are ugly.
@srijanshetty I was under the impression that opposition to such wrapper functions was part of @Tarrasch 's philosophy.
I rather rely on my own zsh fu when it comes to choirs like updating the repositories (nuking the ~/.antigen-hs folder) than relying on some shaky commands of antigen.
http://www.zsh.org/mla/workers/1998/msg01089.html mentions about possible problems with associative arrays in zsh.
_autoenv_stack_entered_mtime on line 60 and 76 seem to be the culprit