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

**URL:** <https://discourse.haskell.org/t/how-to-fix-package-breakage-due-to-file-corruption-stack/2366>\
**Category:** Learn\
**Created:** [April 13, 2021, 9:53pm UTC](https://discourse.haskell.org/t/how-to-fix-package-breakage-due-to-file-corruption-stack/2366 "2021-04-13T21:53:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ketzacoatl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/ketzacoatl/32/1203_2.png) [@ketzacoatl](https://discourse.haskell.org/u/ketzacoatl)\
**Post date:** [April 13, 2021, 9:53pm UTC](https://discourse.haskell.org/t/how-to-fix-package-breakage-due-to-file-corruption-stack/2366/1 "2021-04-13T21:53:42Z")

</div>

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
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-3.0.1.0 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 🙂

---

<div class="post-metadata">

**Author:** ![qrilka](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/qrilka/32/25_2.png) [@qrilka](https://discourse.haskell.org/u/qrilka)\
**Post date:** [April 14, 2021, 8:46pm UTC](https://discourse.haskell.org/t/how-to-fix-package-breakage-due-to-file-corruption-stack/2366/2 "2021-04-14T20:46:35Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![ketzacoatl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/ketzacoatl/32/1203_2.png) [@ketzacoatl](https://discourse.haskell.org/u/ketzacoatl)\
**Post date:** [April 14, 2021, 9:26pm UTC](https://discourse.haskell.org/t/how-to-fix-package-breakage-due-to-file-corruption-stack/2366/3 "2021-04-14T21:26:49Z")

</div>

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
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.

---

<div class="post-metadata">

**Author:** ![qrilka](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/qrilka/32/25_2.png) [@qrilka](https://discourse.haskell.org/u/qrilka)\
**Post date:** [April 15, 2021, 8:38am UTC](https://discourse.haskell.org/t/how-to-fix-package-breakage-due-to-file-corruption-stack/2366/4 "2021-04-15T08:38:47Z")

</div>

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
