Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch mode reports the Show instance of ConstructPlanFailed, instead of a readable error #5978

Closed
koterpillar opened this issue Dec 20, 2022 · 2 comments

Comments

@koterpillar
Copy link
Contributor

General summary/comments (optional)

When using --file-watch, and the build plan cannot be constructed, Stack displays an internal error representation instead of a readable error message.

Steps to reproduce

In an empty directory, create stack.yaml with no dependencies, e.g.

resolver: ghc-9.2.4
packages:
- .

Create a Cabal file referencing an unavailable package, e.g.

cabal-version: 1.12

name:           test
version:        0.1.0.0
synopsis:       Test
description:    Test
author:         Test
maintainer:     test@example.com
build-type:     Simple

executable main
  main-is: Main.hs
  hs-source-dirs:
      .
  build-depends:
      base >=4.7 && <5
    , microlens-platform
  default-language: Haskell2010

Run stack build --file-watch.

Expected

Readable error message, such as in the case of stack build without watch:

Error: [S-4804]
       Stack failed to construct a build plan.
       
       While constructing the build plan, Stack encountered the following errors:
       
       In the dependencies for test-0.1.0.0:
           microlens-platform needed, but the Stack configuration has no specified version (latest matching version is 0.4.3.3)
       needed since test is a build target.

Actual

Only an internal error representation shown:

ConstructPlanFailed [UnknownPackage (PackageName "microlens-platform"),DependencyPlanFailures (Package {packageName = PackageName "test", packageVersion = mkVersion [0,1,0,0], packageLicense = Left NONE, packageFiles = <GetPackageFiles>, packageDeps = fromList [(PackageName "base",DepValue {dvVersionRange = IntersectVersionRanges (OrLaterVersion (mkVersion [4,7])) (EarlierVersion (mkVersion [5])), dvType = AsLibrary}),(PackageName "microlens-platform",DepValue {dvVersionRange = OrLaterVersion (mkVersion [0]), dvType = AsLibrary})], packageUnknownTools = fromList [], packageAllDeps = fromList [PackageName "base",PackageName "microlens-platform"], packageGhcOptions = [], packageCabalConfigOpts = [], packageFlags = fromList [], packageDefaultFlags = fromList [], packageLibraries = NoLibraries, packageInternalLibraries = fromList [], packageTests = fromList [], packageBenchmarks = fromList [], packageExes = fromList ["main"], packageOpts = <GetPackageOpts>, packageHasExposedModules = False, packageBuildType = Simple, packageSetupDeps = Nothing, packageCabalSpec = CabalSpecV1_12}) (fromList [(PackageName "microlens-platform",(OrLaterVersion (mkVersion [0]),Just (mkVersion [0,4,3,3],8ef4c8d5b9e0948489aa0b0b6a90c3d0c52e768e4e1f0e3f87697f6abd5d88fd,2930),NotInBuildPlan))])] "/Users/akotlyarov/xaos/stack-construct-plan/stack.yaml" "/Users/akotlyarov/.stack/" (MonoidMap (fromList [(PackageName "base",(First {getFirst = Nothing},[(PackageIdentifier {pkgName = PackageName "test", pkgVersion = mkVersion [0,1,0,0]},IntersectVersionRanges (OrLaterVersion (mkVersion [4,7])) (EarlierVersion (mkVersion [5])))])),(PackageName "microlens-platform",(First {getFirst = Nothing},[(PackageIdentifier {pkgName = PackageName "test", pkgVersion = mkVersion [0,1,0,0]},OrLaterVersion (mkVersion [0]))]))])) (fromList [PackageName "test"]) (fromList [])
Type help for available commands. Press enter to force a rebuild.

Stack version

stack --version
Version 2.9.3, Git revision 6cf638947a863f49857f9cfbf72a38a48b183e7e x86_64 hpack-0.35.1

Method of installation

  • Official binary, downloaded via haskellstack.org or from Stack's repository
@mpilgrem mpilgrem changed the title Watch mode reports a wall of text starting with ConstructPlanFailed instead of a readable error Watch mode reports the Show instance of ConstructPlanFailed, instead of a readable error Dec 20, 2022
@mpilgrem mpilgrem self-assigned this Dec 20, 2022
@mpilgrem
Copy link
Member

@koterpillar, thanks for reporting. The problem is that - somehow - the Show instance of ConstructPlanFailed is being reported instead of its 'pretty' form. There is only one place in Stack's code where ConstructPlainFailed is being thrown expressly, and it is thrown as a 'PrettyException', so this must be something to do with how --file-watch handles exceptions. That will take a little investigation by me.

mpilgrem added a commit that referenced this issue Dec 20, 2022
Fix #5978 Handle pretty exceptions with `--file-watch`
@mpilgrem
Copy link
Member

@koterpillar, I am sorry this was not picked up before Stack 2.9.3 was released, but it is now fixed in the master branch version of Stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants