4

I've had nothing but trouble using cabal, not sure if it's due to a lack of understanding, or a faulty mental model, but things have been tough.

At the moment I'm just trying to get ghc-mod to work for my vim plugins. It usually works for a day or two and then starts failing for seemingly no reason with an error, the error I receive seems to change from time to time, right now I'm getting this one:

$ ghc-mod check Main.hs
ghc-mod: /Users/chris/.stack/snapshots/x86_64-osx/lts-6.15/7.10.3/pkgdb/package.cache: 
GHC.PackageDb.readPackageDb: inappropriate type (Not a valid Unicode code point!)

Any ideas about how to fix this sort of thing? I've tried installing it again, but I get this (I think my cabal packages are all screwed up but don't know how to fix it):

$ cabal install ghc-mod
Resolving dependencies...
Downloading haskell-src-exts-1.17.1...
Configuring haskell-src-exts-1.17.1...
Failed to install haskell-src-exts-1.17.1
Build log ( /Users/chris/.cabal/logs/haskell-src-exts-1.17.1.log ):
cabal: Entering directory '/var/folders/6l/rdh2g5wn41s8vxchngkt02_c0000gn/T/cabal-tmp-45583/haskell-src-exts-1.17.1'
Configuring haskell-src-exts-1.17.1...
cabal: The program 'happy' version >=1.19 is required but it could not be
found.
cabal: Leaving directory '/var/folders/6l/rdh2g5wn41s8vxchngkt02_c0000gn/T/cabal-tmp-45583/haskell-src-exts-1.17.1'
cabal: Error: some packages failed to install:
ghc-mod-5.6.0.0 depends on haskell-src-exts-1.17.1 which failed to install.
haskell-src-exts-1.17.1 failed during the configure step. The exception was:
ExitFailure 1
hlint-1.9.35 depends on haskell-src-exts-1.17.1 which failed to install.

Edit: Looked away for a second and tried again, now I'm getting this error, getting kinda sick of cabal changing its mind all the time:

$ ghc-mod check Main.hs
[1 of 5] Compiling CabalHelper.Common ( CabalHelper/Common.hs, /Users/chris/.ghc-mod/cabal-helper/CabalHelper/Common.o  )
[2 of 5] Compiling CabalHelper.Licenses ( CabalHelper/Licenses.hs, /Users/chris/.ghc-mod/cabal-helper/CabalHelper/Licenses.o  )

CabalHelper/Licenses.hs:53:18: error:
Ambiguous occurrence ‘lookupInstalledPackageId’
It could refer to either ‘Distribution.Simple.PackageIndex.lookupInstalledPackageId’,
imported from ‘Distribution.Simple.PackageIndex’ at CabalHelper/Licenses.hs:24:1-39
or ‘CabalHelper.Licenses.lookupInstalledPackageId’,
defined at CabalHelper/Licenses.hs:38:1

CabalHelper/Licenses.hs:74:10: error:
Ambiguous occurrence ‘lookupInstalledPackageId’
It could refer to either ‘Distribution.Simple.PackageIndex.lookupInstalledPackageId’,
imported from ‘Distribution.Simple.PackageIndex’ at CabalHelper/Licenses.hs:24:1-39
or ‘CabalHelper.Licenses.lookupInstalledPackageId’,
defined at CabalHelper/Licenses.hs:38:1
ghc-mod: readCreateProcess: /Users/chris/.stack/snapshots/x86_64-osx/lts-6.15/7.10.3/libexec/cabal-helper-wrapper "--with-ghc=/usr/local/bin/ghc" "--with-ghc-pkg=/usr/local/bin/ghc-pkg" "--with-cabal=cabal" "/Users/chris/dev/formatter" "/Users/chris/dev/formatter/.stack-work/dist/x86_64-osx/Cabal-1.24.0.0" "package-db-stack" "entrypoints" "source-dirs" "ghc-options" "ghc-src-options" "ghc-pkg-options" "ghc-merged-pkg-options" "ghc-lang-options" "licenses" "flags" "config-flags" "non-default-config-flags" "compiler-version" (exit 1): failed
sjakobi
  • 3,546
  • 1
  • 25
  • 43
Chris Penner
  • 1,881
  • 11
  • 15
  • 1
    I know this is going to sound very not fun, but allow me to recommend you use [`stack`](https://docs.haskellstack.org/en/stable/README/). It makes it _much_ easier to get out of cabal hell with LTS snapshots... – Alec Oct 11 '16 at 01:40
  • Can you tell us a little more about your working environment. I saw the ".stack" in one of the paths in the first transcript that you included above and assumed that you *were* already using stack (in addition to cabal somehow) but maybe that's wrong. – Dave Compton Oct 11 '16 at 04:05
  • I'm using stack for the majority of my stuff, it didn't seem to be working and I figured it would be easier to get help with cabal, maybe I'm incorrect, At any rate, I've run stack install ghc-mod and have added ~/.local/bin/ to my path, but I still get errors most of the time – Chris Penner Oct 12 '16 at 04:15
  • And of course I updated to MacOs Sierra this week, so that's causing all sorts of problems with stack now. – Chris Penner Oct 12 '16 at 04:31
  • Same problem here with neovim, ghci has no problems but ghc-mod says with the same error messages that this is not ok. Checking the versions, my ghc and ghci are 8.0.1 while ghc-mod refers to 7.10.3. Maybe upgrading to a newer ghc-mod helps? (Cannot remember how to do the upgrade -> it will take some time to try.) – Gspia Oct 28 '16 at 11:46
  • Ah, it was just cabal update; cabal install ghc-mod and it seems that the above license-error-msg went away. Cannot tell thou, if the problem was because of a mixture of compiler and its tools (my path seemed to pick something from stack-related directories pointing to older version and something elsewhere). Cabal update compiled the tools with ghc 8.0.1. – Gspia Oct 28 '16 at 12:24
  • Interesting, I'm also using neovim, so maybe that's related, I'll try out a few things. – Chris Penner Oct 29 '16 at 17:49

1 Answers1

0

This error was caused by having a mismatch between my local stack ghc version and the global ghc-mod ghc version, I updated the ghc version in the stack project to latest and everything is working fine.

Chris Penner
  • 1,881
  • 11
  • 15