Skip to content

Add parse error location to unparsable environment file warning#11996

Merged
mergify[bot] merged 8 commits into
haskell:masterfrom
wasimat404:fix/11963-env-file-parse-error
Jul 26, 2026
Merged

Add parse error location to unparsable environment file warning#11996
mergify[bot] merged 8 commits into
haskell:masterfrom
wasimat404:fix/11963-env-file-parse-error

Conversation

@wasimat404

Copy link
Copy Markdown
Contributor

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
Contributor Author

@zlonast Thanks for the nudge:)

@wasimat404
wasimat404 marked this pull request as ready for review June 26, 2026 23:36
@zlonast zlonast added squash+merge me Tell Mergify Bot to squash-merge and removed attention: needs-review labels Jul 24, 2026
@mergify mergify Bot added ready and waiting Mergify is waiting out the cooldown period merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days queued labels Jul 24, 2026
@mergify

mergify Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 1 hour 48 minutes 3 seconds in the queue, including 1 hour 37 minutes 14 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection] (documentation)
  • any of [🛡 GitHub branch protection]:
    • check-success = Doctest Cabal
    • check-neutral = Doctest Cabal
    • check-skipped = Doctest Cabal
  • any of [🛡 GitHub branch protection]:
    • check-success = Meta checks
    • check-neutral = Meta checks
    • check-skipped = Meta checks
  • any of [🛡 GitHub branch protection]:
    • check-success = docs/readthedocs.org:cabal
    • check-neutral = docs/readthedocs.org:cabal
    • check-skipped = docs/readthedocs.org:cabal
  • any of [🛡 GitHub branch protection]:
    • check-success = Validate post job
    • check-neutral = Validate post job
    • check-skipped = Validate post job
  • any of [🛡 GitHub branch protection]:
    • check-success = fourmolu
    • check-neutral = fourmolu
    • check-skipped = fourmolu
  • any of [🛡 GitHub branch protection]:
    • check-success = hlint
    • check-neutral = hlint
    • check-skipped = hlint
  • any of [🛡 GitHub branch protection]:
    • check-success = Bootstrap post job
    • check-neutral = Bootstrap post job
    • check-skipped = Bootstrap post job
  • any of [🛡 GitHub branch protection]:
    • check-success = whitespace
    • check-neutral = whitespace
    • check-skipped = whitespace
  • any of [🛡 GitHub branch protection]:
    • check-success = Check sdist post job
    • check-neutral = Check sdist post job
    • check-skipped = Check sdist post job
  • any of [🛡 GitHub branch protection]:
    • check-success = Changelogs
    • check-neutral = Changelogs
    • check-skipped = Changelogs

@mergify
mergify Bot merged commit 47209d3 into haskell:master Jul 26, 2026
92 of 94 checks passed
@mergify mergify Bot removed the queued label Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days ready and waiting Mergify is waiting out the cooldown period squash+merge me Tell Mergify Bot to squash-merge

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)

4 participants