Stack InvalidRelFile error when adding local package - haskell

I'm having this strange issue : I'm trying to add a local package to my stack file and I get the following error. when I try to build it (stack build) it kind of work but fails suggesting me to use stack solver but when I run stack solver I got the following error
Using configuration file: stack.yaml
InvalidRelFile "/home/max/devel/sql-fragment/sql-fragment.cabal"
My stack file looks like
flags: {}
packages:
- '.'
- ../sql-fragment
extra-deps:
...
I'm on Ubuntu 15.02 trying to use GHC-7.8.4 and stack 1.0.4
The two packages, sql-fragment and sql-fragment-mysql-simple can be found on github.

It's probably a bug in stack. I managed to find a workaround by moving sql-fragment directory into sql-fragment-mysql-simple, change ../sql-fragment to sql-fragment in the stack file launch the solver -stack solver --update-config and it works. What is strange is, I add to properly move the directory to make it work (just creating a symbolic link woudn't work) and once the solver has done its job. I moved sql-fragment where it was, revert the path to ../sql-fragment and stack build works perfectly ;-).

Fixed with this commit. https://github.com/commercialhaskell/stack/commit/42a61fb278aeb99ad61bb088da9a87b2313ac325
The issue tracker is a better place for this.

Related

Haskell stack gives InvalidRelDir error no matter the input

I am encountering the following error every time I try to use stack except for stack --version:
PS D:\Currentdir\version2\code> stack update
InvalidRelDir "D:\\Currentdir\\code\\.stack-work"
PS D:\Currentdir\version2\code> stack clean
InvalidRelDir "D:\\Currentdir\\version2\\code\\.stack-work"
PS D:\Currentdir\version2\code> stack test
InvalidRelDir "D:\\Currentdir\\version2\\code\\.stack-work"
PS D:\Currentdir\version2\code>
I think I deleted the .stack/work subfolder in one of my projects (from within Windows 10 file explorer), and this might be causing the problems since the commands might look for that specific folder, and since stack test did work before.
There are however .stack-work subfolders in other projects such as in the one indicated above. So I am not entirely sure.
I just discovered that my stack has somehow been set to look for a .stack-work folder that is within a specific folder, as seen below where I have tried to navigate first to other folders and after that to that particular folder in windows powershell:
PS D:\Redo_haskell_folder\code> stack path
InvalidRelDir "D:\\HaskellAppFolder\\version2\\code\\.stack-work"
PS D:\Redo_haskell_folder\code> stack --stack-root STACK-ROOT
option --stack-root: InvalidAbsDir "STACK-ROOT"
PS C:\sr> stack path
InvalidRelDir "D:\\HaskellAppFolder\\version2\\code\\.stack-work"
PS D:\HaskellAppFolder\version2\code> stack path
InvalidRelDir "D:\\HaskellAppFolder\\version2\\code\\.stack-work"
I have tried the following steps to troubleshoot the "InvalidRelDir" error when running stack update or stack clean, I:
Made sure that I am using the latest version of stack by running stack --version and tried updating stack with stack upgrade.
Checked the contents of my stack.yaml file to make sure that it is correct and specifies the correct dependencies and packages for my project. It is just the one initilialized with the stack init in my current folder.
Ran stack init in my project directory to create a new stack.yaml file and configure my project for use with stack. This gives back the same error message.
Tried to delete the .stack-work directory using Remove-Item -Recurse -Force .stack-work (I am using windows 10 and powershell terminal) and ran stack update or stack clean again to see if the issue is resolved. The remove-command caused same InvalidRelDir error.
Tried to change the permission of the folders I am working in, within the windows 10 explorer, by un-checking the 'Read only'-permission. The problem persists.
I also tried suing stack-root I get the following in the powershell prompt
code> stack --stack-root STACK-ROOT
option --stack-root: InvalidAbsDir "STACK-ROOT"
Despite these efforts, I am still encountering the "InvalidRelDir" error. I haven't been able to find any posts that mentions the same problem they encountered, any good ideas?
EDIT
Since I have gotten very few responses, perhaps I could help open op the trouble shooting by asking about the default location for stack root.
Furthermore is there a way to un-install only stack rather than all of the ghc and cabal packages that comes with it?
EDIT EDIT
Or if none of the above works, would there be a way to uninstall the above and re-install in such a way that I would have taken into consideration the multiple .stack-work folders that might have been created from my trouple shooting proces.
EDIT x3
I finally found the InvalidRelDir in the documentation - not for stack as such but at hackage . As far as I can see this is a haskell documentation, and somehow the stack build is using the function parselRelDir described as:
parseRelDir :: MonadThrow m => FilePath -> m (Path Rel Dir)
Convert a relative FilePath to a normalized relative dir Path.
Throws: InvalidRelDir when the supplied path:
is not a relative path
is ""
contains a .. path component representing the parent directory
is not a valid path (See isValid)
I suspect that I get the error because the stack library is using this library as well. If any of you find this to be an incorrect tenet or have any suggestions about how to proceed from here without uninstalling all of stack it will be appreciated.
As seen in the post above, I have now narrowed the problem down even further, to some kind of 'pointer' to an 'old' or wrong directory. And I think my question therefore is: "Is there a way to 'reset' the .stack-workfolder that stack is looking for with the parseRelDir function mentioned before?"
I have now uninstalled stack according to: this and have in that process also removed C:\sr and the %AppData%\Roaming\stack.
I have then installed it with this windows package as recommended from official documentary.
I do however still get the same error now that I have installed it again.
EDIT x4
I have now made progress! I went to "Edit System Variables" and edited "STACK ROOT" to C:\sr and C:\sr\.stack-work but got the following error with the output of those paths respectively
PS D:\Redo_haskell_folder\code> stack path InvalidRelDir "C:\\sr"
So now that I know why the pointer kept being the same despite re-installing stack, I now have to find out the following: What is the correct path for "STACK ROOT"
PS: after reinstalling the C:\sr is empty except for a config.yaml file
I got in touch with the stack-support and used the following 'reset of the STACK_ROOT' to solve the issue.
STACK_ROOT is an environment variable that specifies the location of
the Stack Root directory. See
https://docs.haskellstack.org/en/stable/environment_variables/#stack_root.
See also:
https://docs.haskellstack.org/en/stable/global_flags/#the-stack-root-option.
On Windows, the default value is C:\sr (because some Windows operating
systems have problems with long paths). Stack will populate the Stack
root the first time it needs the contents of the Stack root.
❯ echo $Env:STACK_WORK
> $Env:STACK_WORK="C:\temp"
> echo $Env:STACK_WORK
C:\temp
> stack path --dist-dir
InvalidRelDir "C:\\temp"
> $Env:STACK_WORK=""
> stack path --dist-dir
.stack-work\dist\8a54c84f

weird error with haskell-stack. it doesn't install anything anymore

I get an error with stack, while trying to install a package.
Run from outside a project, using implicit global project config
Using resolver: lts-8.0 from implicit global project's config file: /home/chuck/.stack/global-project/stack.yaml
Invalid package ID: "array-0.5.1.1 base-4.9.1.0 binary-0.8.3.0 bytestring-0.10.8.1"
stack --version works:
Version 0.1.10.0 x86_64
and stack setup returns this:
Run from outside a project, using implicit global project config
Using resolver: lts-8.0 from implicit global project's config file: /home/chuck/.stack/global-project/stack.yaml
stack will use a locally installed GHC
For more information on paths, see 'stack path' and 'stack exec env'
To use this GHC and packages outside of a project, consider using:
stack ghc, stack ghci, stack runghc, or stack exec
I reinstalled stack and I get the same error after the new installation. So, I don't know what I'm doing wrong. I need it for using atom.
EDIT
Stack.yaml:
# This is the implicit global project's config file, which is only used when
# 'stack' is run outside of a real project. Settings here do _not_ act as
# defaults for all projects. To change stack's default settings, edit
# '/home/chuck/.stack/config.yaml' instead.
#
# For more information about stack's configuration, see
# https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md
#
flags: {}
extra-package-dbs: []
packages: []
extra-deps: []
resolver: lts-8.0
After trying a many things I "found the answer".
The problem was, as epsilonhalbe saw, that I had an old version. So I tried to do this wget -qO- https://get.haskellstack.org/ | sh and it didn't work, because I had stack on /usr/bin/ so, I removed stack and then tried again wget -qO- https://get.haskellstack.org/ | sh. I added $HOME/.local/bin/ to the path, and it's working properly.
I hope it can help someone
EDIT
There's a new version of stack, but ghc-mod just works until the lts-9.0 of stack. So, if you're having troubles with ghc-modand your stack version is over 8.0.2 then:
nano /Users/USERNAME/.stack/global-project/stack.yaml
and replace resolver: --- for resolver: lts-9.0
Then, on the terminal stack solver and it's gonna work :)
I was blocked by the same problem, unless I check which stack (or use where stack as alternative) and I found that I'm using an old version of stack which I installed somehow, and the new version was never accessed when I typed the stack command ...
Here is the situation when I realized the problem..
If you check stack --version and get something like Version 0.1.10.0 x86_64, then it is far away from the current version, the current version I'm using (when answering this question) is Version 1.3.3, Git revision 078cfadeb37a39501eae24732e5c757cc8aca31b x86_64 hpack-0.17.0
If you had confirmed that you are not using the wrong one stack, but the stack version is still too low, you can use stack upgrade --git to upgrade your stack to the latest version from git (notice that this will take a while).
Hope this helpful.

Haskell stack build error "No local directories found as children"

When running stack build --no-terminal --install-ghc, I run into Error parsing targets: No local directories found as children.
I can understand what it means, but why does it happen? I haven't read anywhere in the Stack manual about having to create extra directories ..
Thanks in advance
What's your stack version? Can you still reproduce this with the latest?
This means that it is parsing an argument as if it is a TARGET, but isn't finding the dir. I think in old versions of stack, unrecognized flags would get parsed this way. So, if you're using a command intended for newer stack, this error can happen.

Stack/Docker/IHaskell weird behaviour

I have a package with bunch of *.c and *.cpp files, listed inside c-sources field of *.cabal file. I need to include it inside a project with IHaskell and some other packages. Everything works fine, and builds without a problem. stack exec ghci works fine and I can import modules and execute any code. stack ghci though throws some weird errors, like this:
In file included from <command-line>:10:0:
/...blabla.../.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/autogen/cabal_macros.h:157:0:
note: this is the location of the previous definition
#define CURRENT_PACKAGE_KEY "blabla"
^
And stack ghci inside my package complains about symbols exported from its C code. Another weird thing is that symbols depend on the order of exposed-modules in the configuration, so the error goes away if I put my *.hs module on top of others, but if I have two *.hs files importing from the same *.c file, it won't work! stack exec jupyter -- console --kernel haskell starts, but immediately throws unknown symbol error if I try to run some code from my package, always the same though.
I have a docker image based on fpco/stack-build, which just installs jupyter and other necessary stuff. I use lts-3.0 snapshot, if it's somehow relevant.
What is going on?
There have been a lot of improvements made recently to stack ghci, which is still mostly a work in progress. I'd recommend testing out stack master, and if the problem still exists opening a Github issue.

Synastic errors - Vim, Stack, Haskell development

I am using stack for my Haskell development and Syntastic for my error checking when editing in Vim. I have not installed the haskell-platform, instead, I use a stack build --install-ghc to get my environment up and running using the supported GHC, cabal and lts packages.
Normally, I use a cabal sandbox and syntastic works well with this. I see when I do a let g:syntastic_debug=3 in Vim, syntastic runs a cabal configure which checks if the project dependencies are installed and then goes ahead and does some hlint, hdevtools and ghc-mod magic to give me some warnings and/or error messages.
Now, here is my problem. Since my cabal setup (installed from stack) doesn't know about my dependencies installed at .stack-work or .stack (not sure), it complains that I am missing necessary packages and blows up when syntastic runs in my Vim instance.
Trying to run a stack exec -- cabal configure returns the following error:
Use of GHC's environment variable GHC_PACKAGE_PATH is incompatible with Cabal. use the flag --package-db to specify a package database (it can be used multiple times).
I haven't found out how to pass the --package-db option with the correct database. Nothing seems to work there.
So, the quetion - will successfully running a stack exec -- cabal configure, avoiding the GHC_PACKAGE_PATH issue get me to a working setup? Can anyone give me some direction here?
hdevtools works. See here: http://seanhess.github.io/2015/08/05/practical-haskell-editors.html
I'm planning on keeping that up to date as new tools come out (like stack-ide).
This blogpost gives a nice introduction as well. Things change quickly in the haskell world and ghc-mod seems to be working well with stack now. The setup from the post requires neovim though.
The setup from the post worked perfectly fine for me and found all dependencies within the current stack project.

Resources