Skip to content

Commit 25daf5d

Browse files
jbgiangerman
authored andcommitted
Display err msg when failing to parse cabal files.
1 parent ee2aeb0 commit 25daf5d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/Cabal2Nix.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module Cabal2Nix (cabal2nix, gpd2nix, Src(..), CabalFile(..), CabalFileGenerator(..), cabalFilePath, cabalFilePkgName) where
66

7-
import Distribution.PackageDescription.Parsec (readGenericPackageDescription, parseGenericPackageDescriptionMaybe)
7+
import Distribution.PackageDescription.Parsec (readGenericPackageDescription, parseGenericPackageDescription, runParseResult)
88
import Distribution.Verbosity (normal)
99
import Distribution.Text (disp)
1010
import Distribution.Pretty (pretty)
@@ -79,7 +79,9 @@ cabal2nix src = \case
7979
(OnDisk path) -> fmap (gpd2nix src Nothing)
8080
$ readGenericPackageDescription normal path
8181
(InMemory gen _ body) -> fmap (gpd2nix src (genExtra <$> gen))
82-
$ maybe (error "Failed to parse in-memory cabal file") pure (parseGenericPackageDescriptionMaybe body)
82+
$ case (runParseResult (parseGenericPackageDescription body)) of
83+
(_, Left (_, err)) -> (error ("Failed to parse in-memory cabal file: " ++ show err))
84+
(_, Right desc) -> pure desc
8385

8486
gpd2nix :: Maybe Src -> Maybe NExpr -> GenericPackageDescription -> NExpr
8587
gpd2nix src extra gpd = mkFunction args $ toNix gpd $//? (toNix <$> src) $//? extra

0 commit comments

Comments
 (0)