How to fix package breakage due to file corruption? (stack)

Not often, but once in a while I will run into some filesystem corruption or similar, which removes a couple files in stack’s local file cache. For example:

haskell-src-exts> happy: ~/.stack/snapshots/x86_64-linux-nix/c1905bb1b17a991e3ffae2ea917ec6a38b82e6dcad26b163aaf8bfe9fb27ebb0/8.8.3/share/x86_64-linux-ghc-8.8.3/happy-1.19.12/HappyTemplate-arrays-coerce: openFile: does not exist (No such file or directory)
--  While building package haskell-src-exts-1.22.0 using:
      ~/.stack/setup-exe-cache/x86_64-linux-nix/Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.3 --builddir=.stack-work/dist/x86_64-linux-nix/Cabal- build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1
Progress 1/4

In particular: openFile: does not exist (No such file or directory. A file (or a couple) are missing. Can stack review and repair? Or is there a thing I can do to trigger the rebuild for the problem package(s)?

I can reset the cache, and in the past I may have even reset the one problem package, but I never remember what to do for a simple/precise fix when stack finds some files are missing. Is this where I should be using stack clean, removing some file/directory, editing some JSON file, or some other stack foo command?

Thanks :slight_smile:

1 Like

@ketzacoatl with packages you could do something like stack exec ghc-pkg unregister <PKGNAME> but in this case happy is an executable, so you need to drop the executable (delete the file returned by stack exec which happy) and Stack should reinstall it, if I not misremember anything.

1 Like

Hey, thanks for the guidance @qrilka. It’s good to be reminded about ghc-pkg, I do believe someone has recommended that to me in the past. In this case, removing the happy bin didn’t help haskell-src-exts:

haskell-src-exts> configure   
haskell-src-exts> Configuring haskell-src-exts-1.22.0...
haskell-src-exts> Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.3: The program 'happy' version >=1.19 is
haskell-src-exts> required but it could not be found.

I’ve used my hammer to work-around, but also curious if there are more precise ways of recovering or asking stack to do rebuild. It seems like ghc-pkg unregister is the way for most packages, but with happy there is a special case and chicken/egg problem.

The problem with happy is that it’s not a Cabal library, Stack has some workarounds for installing executables but in this case it looks like it didn’t understand that it needs to reinstall happy for some reason, I’d attempt to run stack build happy in that case

1 Like