I run stack ghci into ghci environment, and want run test using :!stack test, but it failed.
Control.Exception.Safe.throwString called with:
In Nix shell but reExecL is False
Called from:
throwString (src/Stack/Runners.hs:120:18 in stack-2.1.3-F7MWgE4o5YoAS7Zt7rEwj6:Stack.Runners)
How to fix this?
Hey @leptonyu - sorry for the delayed response.
Were you able to figure this out? I'm having trouble reproducing the error, so it'd help if you could share a link to a git repo that fails with the message in your output (or steps to build one).
Which versions of stack and nix do you have installed?
@mattaudesse
plz use repo to test.
My stack version is 2.13 and nix version is 2.2.2
stack ghci
Configuring GHCi with the following packages: boots, boots-app
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /Users/daniel/Documents/code/shell/ghci
[1 of 8] Compiling Boots.App.Internal ( /Users/daniel/Documents/code/boots/boots-app/src/Boots/App/Internal.hs, interpreted )
[2 of 8] Compiling Boots.Factory ( /Users/daniel/Documents/code/boots/boots/src/Boots/Factory.hs, interpreted )
[3 of 8] Compiling Boots.App ( /Users/daniel/Documents/code/boots/boots-app/src/Boots/App.hs, interpreted )
[4 of 8] Compiling Boots.Factory.Salak ( /Users/daniel/Documents/code/boots/boots-app/src/Boots/Factory/Salak.hs, interpreted )
[5 of 8] Compiling Boots.Factory.Vault ( /Users/daniel/Documents/code/boots/boots-app/src/Boots/Factory/Vault.hs, interpreted )
[6 of 8] Compiling Boots.Factory.Logger ( /Users/daniel/Documents/code/boots/boots-app/src/Boots/Factory/Logger.hs, interpreted )
[7 of 8] Compiling Boots.Factory.Application ( /Users/daniel/Documents/code/boots/boots-app/src/Boots/Factory/Application.hs, interpreted )
[8 of 8] Compiling Boots ( /Users/daniel/Documents/code/boots/boots-app/src/Boots.hs, interpreted )
Ok, 8 modules loaded.
Loaded GHCi configuration from /private/var/folders/lh/6nc659bd3hx059sw2cn4zhjr0000gn/T/haskell-stack-ghci/0e0d4d57/ghci-script
λ> :!stack test
Control.Exception.Safe.throwString called with:
In Nix shell but reExecL is False
Called from:
throwString (src/Stack/Runners.hs:120:18 in stack-2.1.3-F7MWgE4o5YoAS7Zt7rEwj6:Stack.Runners)
and I put some config in the ~/.stack/config.yaml
nix:
enable: true
add-gc-roots: true
packages:
- zlib
- libffi
- darwin.apple_sdk.frameworks.CoreServices
- darwin.apple_sdk.frameworks.Foundation
- darwin.apple_sdk.frameworks.Cocoa
Thanks @leptonyu - with those steps I can definitely reproduce the problem now.
I experimented a bit to see if I could fix it easily but based on this commit I think @snoyberg might be the best person to comment.
I'm guessing you've already tried this, but does stack test work for you when run outside of stack ghci? It does for me.
@mattaudesse Yes, I can work with 2 windows open.
I have two scenarios, but the second has no workaround.
First is some customized commands, like
def ho \x -> return $ ":!stack exec hoogle -- " ++ x
This can be replaced by hoogle.
Second is ghcid, it has an option --test which can set command to run after successful loading.
So I need run stack in stack.
ghcid --test ':!stack test' --reload .
Both the Docker and Nix codepaths (which both leverage the same reExecL feature) are notoriously susceptible to breaking in weird ways when their environment is modified in unexpected ways. We've tried to lock things down to ensure that they are run in normal environments. The exact thing you're trying to accomplish _may_ run just fine, but it's untested, and I'd rather encourage people towards using tested codepaths than try to figure out exceptions we can start adding.
If you really want to, deleting the relevant env vars from within ghci would probably help in your use case.
Thanks, it works by removing STACK_IN_NIX_SHELL.
ghcid --test ':!unset STACK_IN_NIX_SHELL && stack test' --reload .
@leptonyu how could I remove STACK_IN_NIX_SHELL when doing a stack build ?
@razvan-panda I'm sorry that I have no idea how to set directly using stack.
I'm running into this, now, with any stack command requiring the runner (install, build, setup) from a global project. I haven't tried it in a project, yet.
My workaround is to use a subshell, e.g.:
> (unset STACK_IN_NIX_SHELL; stack install aeson-pretty)
The error
> stack --verbose install aeson-pretty
2.1.3.1 x86_64 hpack-0.32.0
[debug] Checking for project config at: $HOME/stack.yaml
[debug] Checking for project config at: /home/stack.yaml
[debug] Checking for project config at: /stack.yaml
[debug] No project config file found, using defaults.
[debug] SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2019-10-01 12:53:23.34609805 UTC]
[error] Control.Exception.Safe.throwString called with:
In Nix shell but reExecL is False
Called from:
throwString (src/Stack/Runners.hs:120:18 in stack-2.1.3.1-5qMCgpVOl5XrLNYjWC2Mq:Stack.Runners)
Working version
> (unset STACK_IN_NIX_SHELL; stack --verbose install aeson-pretty)
2.1.3.1 x86_64 hpack-0.32.0
[debug] Checking for project config at: $HOME/stack.yaml
[debug] Checking for project config at: /home/stack.yaml
[debug] Checking for project config at: /stack.yaml
[debug] No project config file found, using defaults.
[debug] SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2019-10-01 12:53:23.34609805 UTC]
[debug] Run from outside a project, using implicit global project config
…
I've used nix to install stack, but I'm not running a nix-shell directly — I wonder whether this is the issue? @leptonyu and @razvan-flavius-panda please indicate whether this is the case for you.
(As an aside, please do follow the issue template guidelines, in future)
The env var is being set in a nix expression (line 79). Presumably it shouldn't be set when stack isn't invoked from a nix-shell, even if stack is installed through nix?
@nh2 Does this seem like the correct route to take?
For me stack build succeeds out of a nix-shell but stack build inside a nix-shell fails .
This is my shell.nix https://github.com/wireapp/wire-server/blob/develop/shell.nix
and this is my stack.yaml https://github.com/wireapp/wire-server/blob/develop/stack.yaml
My previous workflow was to open nix-shell first, as it also installs some other tools like make and docker-compose which we need to run integration tests. But then stack crashes with this exception.
+1 case executing it from _bash_ and not using _nix-shell_. With stack exec -- yesod devel, the above suggested subshell solution would not resolve this: produces the same outcome as without subshell.
However, plain yesod devel works.
also get the error on nixos 19.09 with stack exec -- yesod devel
also get the error on nixos 19.09 with stack
exec -- yesod devel
same case here
Even after reverting stack to version 1.9.3, the error persists.