Skip to content

Add parse error location to unparsable environment file warning#11996

Open
wasimat404 wants to merge 8 commits into
haskell:masterfrom
wasimat404:fix/11963-env-file-parse-error
Open

Add parse error location to unparsable environment file warning#11996
wasimat404 wants to merge 8 commits into
haskell:masterfrom
wasimat404:fix/11963-env-file-parse-error

Conversation

@wasimat404

Copy link
Copy Markdown

Fixes #11963.

When a GHC environment file cannot be parsed, cabal previously warned only that the file "is unparsable", giving no indication of where or why. The underlying parser already produces a Parsec error carrying the line, column, and the unexpected/expected tokens, but that information was discarded at the warning site in getExistingEnvEntries. This surfaces it.

Before:

Warning: The environment file /home/user/.ghc/.../environments/default is unparsable. Libraries cannot be installed.

After:

Warning: The environment file /home/user/.ghc/.../environments/default is unparsable. Libraries cannot be installed.
"/home/user/.ghc/.../environments/default" (line 1, column 1):
unexpected 't'
expecting "--", "package-id", "global-package-db", "user-package-db", "package-db", "clear-package-db" or end of input

The reporter's case was a stray trailing newline, which the parser reports as "unexpected end of input" at the offending line, so this change points directly at it. The fix is message-only; parser behaviour is unchanged.

Added a cabal-testsuite package test under PackageTests/EnvironmentFile/UnparsableWarning that points cabal at a malformed environment file and asserts the warning includes the location. Verified the test fails on unpatched cabal (the location line is absent) and passes with the change.

QA Notes

Create a malformed GHC environment file, e.g. a file bad.env whose first line is this is not valid. Then run:

cabal install --lib base --package-env=bad.env

The warning should name the parse location, for example:

Warning: The environment file bad.env is unparsable. Libraries cannot be installed.
"bad.env" (line 1, column 1):
unexpected 't'
expecting "--", "package-id", ...

Before this change, only the first line ("is unparsable") was printed, with no location.

When a GHC environment file cannot be parsed, the warning now includes
the line, column, and reason from the underlying parser, instead of only
stating that the file is unparsable.

Fixes haskell#11963

Signed-off-by: wasimat404 <huaweiwasim7@gmail.com>
Signed-off-by: wasimat404 <huaweiwasim7@gmail.com>
Text.Parsec.Error.ParseError has no Exception instance on older GHCs,
so displayException does not type-check. Its Show instance already
renders the line, column, and reason.

Signed-off-by: wasimat404 <huaweiwasim7@gmail.com>
@wasimat404 wasimat404 marked this pull request as ready for review June 21, 2026 01:02
Comment thread cabal-testsuite/PackageTests/EnvironmentFile/UnparsableWarning/cabal.test.hs Outdated
Assert on the full warning message (location, unexpected character, and
expected tokens) rather than only the line and column, addressing review
feedback on test coverage.

Signed-off-by: wasimat404 <huaweiwasim7@gmail.com>
Record the full warning output to cabal.out rather than asserting on a
substring, so changes to the message are visible in review.

Signed-off-by: wasimat404 <huaweiwasim7@gmail.com>
@wasimat404 wasimat404 marked this pull request as draft June 25, 2026 13:29
Golden output recording fails across the CI matrix for this test because
the install command's surrounding output is not reproducible. Assert on
the key parts of the warning instead.

Signed-off-by: wasimat404 <huaweiwasim7@gmail.com>
Record the install output to cabal.out per review feedback, so changes to
the warning are visible in review.

Signed-off-by: wasimat404 <huaweiwasim7@gmail.com>
@wasimat404

Copy link
Copy Markdown
Author

@zlonast Thanks for the nudge:)

@wasimat404 wasimat404 marked this pull request as ready for review June 26, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

warning message " ... environments/default is unparsable" should give more info (reason/location)

2 participants