[Git][ghc/ghc][wip/romes/fix-6] Improve error message when reading invalid `.target` files
Rodrigo Mesquita (@alt-romes)
gitlab at gitlab.haskell.org
Thu Nov 16 16:11:17 UTC 2023
Rodrigo Mesquita pushed to branch wip/romes/fix-6 at Glasgow Haskell Compiler / GHC
Commits:
20f36c00 by Rodrigo Mesquita at 2023-11-16T16:07:58+00:00
Improve error message when reading invalid `.target` files
A `.target` file generated by ghc-toolchain or by configure can become
invalid if the target representation (`Toolchain.Target`) is changed
while the files are not re-generated by calling `./configure` or
`ghc-toolchain` again. There is also the issue of hadrian caching the
dependencies on `.target` files, which makes parsing fail when reading
reading the cached value if the representation has been updated.
This patch provides a better error message in both situations, moving
away from a terrible `Prelude.read: no parse` error that you would get
otherwise.
Fixes #24199
- - - - -
1 changed file:
- hadrian/src/Hadrian/Oracles/TextFile.hs
Changes:
=====================================
hadrian/src/Hadrian/Oracles/TextFile.hs
=====================================
@@ -19,6 +19,7 @@ module Hadrian.Oracles.TextFile (
queryBuildTarget, queryHostTarget, queryTargetTarget
) where
+import Debug.Trace
import Control.Monad
import qualified Data.HashMap.Strict as Map
import Data.Maybe
@@ -163,14 +164,23 @@ textFileOracle = do
putVerbose $ "| TargetFile oracle: reading " ++ quote file ++ "..."
mtarget <- readMaybe <$> readFile' file
case mtarget of
- Nothing -> error $ "Failed to read a Toolchain.Target from " ++ quote file
+ Nothing -> error $ unlines ["Error parsing a Toolchain.Target from " ++ quote file,
+ "Perhaps the `.target` file is out of date.",
+ "Try re-running `./configure`."
+ ]
+
Just target -> return (target :: Toolchain.Target)
void $ addOracleCache $ \(TargetFile file) -> tf file
-- Orphan instances for (ShakeValue Toolchain.Target)
instance Binary Toolchain.Target where
- put = put . show
- get = read <$> get
+ put = put . show
+ get = fromMaybe (error $ unlines ["Error parsing a toolchain `.target` file from its binary representation in hadrian.",
+ "This is likely caused by a stale hadrian/shake cache",
+ "which has saved an old `.target` file that can't be parsed",
+ "into a more recent `Toolchain.Target`. It is recommended to reset",
+ "by running `./hadrian/build clean`."
+ ]) . readMaybe <$> get
instance Hashable Toolchain.Target where
hashWithSalt s = hashWithSalt s . show
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/20f36c0073ea6cd1baea279eaad9d6b648b8cf13
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/20f36c0073ea6cd1baea279eaad9d6b648b8cf13
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20231116/912249f0/attachment-0001.html>
More information about the ghc-commits
mailing list