[Git][ghc/ghc][wip/romes/24792] ghc-toolchain: Improve parse failure error
Rodrigo Mesquita (@alt-romes)
gitlab at gitlab.haskell.org
Wed May 15 09:31:26 UTC 2024
Rodrigo Mesquita pushed to branch wip/romes/24792 at Glasgow Haskell Compiler / GHC
Commits:
11159352 by Rodrigo Mesquita at 2024-05-15T10:30:40+01:00
ghc-toolchain: Improve parse failure error
Improves the error message for when `ghc-toolchain` fails to read a
valid `Target` value from a file (in doFormat mode).
- - - - -
1 changed file:
- utils/ghc-toolchain/exe/Main.hs
Changes:
=====================================
utils/ghc-toolchain/exe/Main.hs
=====================================
@@ -32,6 +32,7 @@ import GHC.Toolchain.Tools.Nm
import GHC.Toolchain.Tools.MergeObjs
import GHC.Toolchain.Tools.Readelf
import GHC.Toolchain.NormaliseTriple (normaliseTriple)
+import Text.Read (readMaybe)
data Opts = Opts
{ optTriple :: String
@@ -257,9 +258,12 @@ doFormat args = do
case errs of
[] -> do
let opts = foldr (.) id opts0 emptyFormatOpts
- tgt <- read @Target <$> System.IO.readFile (view _formatOptInput opts)
- let file = formatOptOutput opts
- System.IO.writeFile file (show tgt)
+ tgtFile <- System.IO.readFile (view _formatOptInput opts)
+ case readMaybe @Target tgtFile of
+ Nothing -> error $ "Failed to read a valid Target value from " ++ view _formatOptInput opts ++ ":\n" ++ tgtFile
+ Just tgt -> do
+ let file = formatOptOutput opts
+ System.IO.writeFile file (show tgt)
_ -> do
mapM_ putStrLn errs
putStrLn $ usageInfo "ghc-toolchain" formatOpts
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/111593520c0390b3d2110f03c64ba901b43324dd
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/111593520c0390b3d2110f03c64ba901b43324dd
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/20240515/9b739759/attachment-0001.html>
More information about the ghc-commits
mailing list