Skip to content

Commit

Permalink
Improve error message for bad cabal file cabal-version. See haskell#4899
Browse files Browse the repository at this point in the history
.
  • Loading branch information
tbidne committed Feb 28, 2024
1 parent 2acae63 commit 82d7af5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
12 changes: 9 additions & 3 deletions Cabal-syntax/src/Distribution/PackageDescription/Parsec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ parseGenericPackageDescription bs = do
Just csv -> return (Just csv)
Nothing ->
parseFatalFailure zeroPos $
"Unsupported cabal-version " ++ prettyShow v ++ ". See https://github.com/haskell/cabal/issues/4899."
"Unsupported cabal-version specification of cabal format version in cabal-version field: "
++ prettyShow v
++ ".\n"
++ cabalFormatVersionsDesc
_ -> pure Nothing

case readFields' bs'' of
Expand Down Expand Up @@ -175,8 +178,8 @@ parseGenericPackageDescription' scannedVer lexWarnings utf8WarnPos fs = do
-- if it were at the beginning, scanner would found it
when (v >= CabalSpecV2_2) $
parseFailure pos $
"cabal-version should be at the beginning of the file starting with spec version 2.2. "
++ "See https://github.com/haskell/cabal/issues/4899"
"cabal-version should be at the beginning of the file starting with spec version 2.2.\n"
++ cabalFormatVersionsDesc

return v

Expand Down Expand Up @@ -234,6 +237,9 @@ parseGenericPackageDescription' scannedVer lexWarnings utf8WarnPos fs = do
++ "' must use section syntax. See the Cabal user guide for details."
maybeWarnCabalVersion _ _ = return ()

cabalFormatVersionsDesc :: String
cabalFormatVersionsDesc = "Current cabal-version values are listed at https://cabal.readthedocs.io/en/stable/file-format-changelog.html."

goSections :: CabalSpecVersion -> [Field Position] -> SectionParser ()
goSections specVer = traverse_ process
where
Expand Down
3 changes: 2 additions & 1 deletion Cabal-tests/tests/ParserTests/errors/forward-compat.errors
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
VERSION: Just (mkVersion [99999,9])
forward-compat.cabal:0:0: Unsupported cabal-version 99999.9. See https://github.com/haskell/cabal/issues/4899.
forward-compat.cabal:0:0: Unsupported cabal-version specification of cabal format version in cabal-version field: 99999.9.
Current cabal-version values are listed at https://cabal.readthedocs.io/en/stable/file-format-changelog.html.
3 changes: 2 additions & 1 deletion Cabal-tests/tests/ParserTests/errors/forward-compat2.errors
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
VERSION: Just (mkVersion [2,2])
forward-compat2.cabal:5:1: cabal-version should be at the beginning of the file starting with spec version 2.2. See https://github.com/haskell/cabal/issues/4899
forward-compat2.cabal:5:1: cabal-version should be at the beginning of the file starting with spec version 2.2.
Current cabal-version values are listed at https://cabal.readthedocs.io/en/stable/file-format-changelog.html.
3 changes: 2 additions & 1 deletion Cabal-tests/tests/ParserTests/errors/forward-compat3.errors
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
VERSION: Just (mkVersion [99999,99])
forward-compat3.cabal:0:0: Unsupported cabal-version 99999.99. See https://github.com/haskell/cabal/issues/4899.
forward-compat3.cabal:0:0: Unsupported cabal-version specification of cabal format version in cabal-version field: 99999.99.
Current cabal-version values are listed at https://cabal.readthedocs.io/en/stable/file-format-changelog.html.

0 comments on commit 82d7af5

Please sign in to comment.