haskell / error-messages

73 stars 18 forks source link

Add to build-depends in your cabal file #50

Open noughtmare opened 2 years ago

noughtmare commented 2 years ago

A recent question on stackoverflow concerns adding dependencies to the cabal file. The error suggests adding a dependency to the build-depends field:

    src\Main.hs:3:2: error:
    Could not load module `Text.ParserCombinators.Parsec'
    It is a member of the hidden package `parsec-3.1.13.0'.
    Perhaps you need to add `parsec' to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.
  |
3 |  import Text.ParserCombinators.Parsec hiding (spaces)
  |  ^^

However, the .cabal file could contain multiple build-depends fields, so it would be useful if the error message could include slightly more information about the build component and perhaps even a line number in the .cabal file.

That does seem to require some coordination between GHC and Cabal. Maybe with structured error messages GHC could provide a generic "package not found" error and then cabal could intercept that and provide detailed information on how to solve that. That seems like quite a big change, so maybe there is an easier solution?

goldfirere commented 2 years ago

Yes, this seems hard -- but a great suggestion. With today's infrastructure, you'd likely need to invent a new flag for GHC for cabal to use to pass in the info, just so GHC could present it to users in this error message. Once we have the new error infrastructure, though, it would be possible to imagine HLS inserting the info itself.