Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ import Distribution.Simple.Flag
import Distribution.Simple.GHC
( GhcEnvironmentFileEntry (..)
, GhcImplInfo (..)
, ParseErrorExc
, ParseErrorExc (..)
, getGhcAppDir
, getImplInfo
, ghcPlatformAndVersionString
Expand Down Expand Up @@ -1294,12 +1294,13 @@ getExistingEnvEntries verbosity compilerFlavor supportsPkgEnvFiles envFile = do
if (compilerFlavor == GHC || compilerFlavor == GHCJS)
&& supportsPkgEnvFiles
&& envFileExists
then catch ((True,) <$> readGhcEnvironmentFile envFile) $ \(_ :: ParseErrorExc) ->
then catch ((True,) <$> readGhcEnvironmentFile envFile) $ \(ParseErrorExc parseError) ->
warn
verbosity
( "The environment file "
++ envFile
++ " is unparsable. Libraries cannot be installed."
++ " is unparsable. Libraries cannot be installed.\n"
++ show parseError
)
>> return (False, [])
else return (False, [])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cabal-version: 2.4
name: UnparsableWarning
version: 0.1.0.0

executable UnparsableWarning
main-is: Main.hs
hs-source-dirs: app
build-depends: base
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = return ()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is not a valid environment file
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cabal install
Wrote tarball sdist to <ROOT>/cabal.dist/work/./dist/sdist/UnparsableWarning-0.1.0.0.tar.gz
Warning: The environment file <ROOT>/bad.environment is unparsable. Libraries cannot be installed.
"<ROOT>/bad.environment" (line 1, column 1):
unexpected 't'
expecting "--", "package-id", "global-package-db", "user-package-db", "package-db", "clear-package-db" or end of input
Resolving dependencies...
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Test.Cabal.Prelude
import System.FilePath

main = cabalTest $ recordMode DoNotRecord $ do
env <- getTestEnv
let envFile = testCurrentDir env </> "bad.environment"
-- Pointing cabal at an existing, malformed environment file should produce
-- a warning that names the location (line and column) of the parse error
-- and the reason, not merely state that the file is unparsable.
-- See https://github.com/haskell/cabal/issues/11963
res <- cabal' "install" ["--lib", "base", "--package-env=" ++ envFile]
assertOutputContains "is unparsable" res
assertOutputContains "(line 1, column 1):" res
assertOutputContains "unexpected 't'" res
assertOutputContains "expecting" res
10 changes: 10 additions & 0 deletions changelog.d/11963.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
synopsis: Include parse error location in unparsable environment file warning
packages: [cabal-install]
issues: 11963
prs: 11996
---
When a GHC environment file cannot be parsed, the warning now includes the
location (line and column) and the reason for the failure, taken from the
underlying parser, in addition to the existing message. This
makes it possible to find and fix the offending line.
Loading