Skip to content

Commit

Permalink
Print better error on 'ghcup <command> <tool>-<version>'
Browse files Browse the repository at this point in the history
Wrt #180
  • Loading branch information
hasufell committed Jul 20, 2023
1 parent 6623e4b commit b46537f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/GHCup/Download.hs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ getDownloadInfo' t v = do
without_distro = distro_preview (set _Linux UnknownLinux) (const Nothing)

maybe
(throwE NoDownload)
(throwE $ NoDownload (Just v))
pure
(case p of
-- non-musl won't work on alpine
Expand Down
10 changes: 8 additions & 2 deletions lib/GHCup/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,18 @@ instance HFErrorProject NoCompatiblePlatform where
eDesc _ = "No compatible platform could be found"

-- | Unable to find a download for the requested version/distro.
data NoDownload = NoDownload
data NoDownload = NoDownload (Maybe GHCTargetVersion)
deriving Show

instance Pretty NoDownload where
pPrint NoDownload =
pPrint (NoDownload Nothing) =
text (eDesc (Proxy :: Proxy NoDownload))
pPrint (NoDownload (Just tver@(GHCTargetVersion mtarget vv)))
| (Just target) <- mtarget
, target `elem` (T.pack . prettyShow <$> enumFromTo (minBound :: Tool) (maxBound :: Tool))
= text $ "Unable to find a download for " <> T.unpack (tVerToText tver) <> "\n"
<> "Perhaps you meant: 'ghcup <command> " <> T.unpack target <> " " <> T.unpack (prettyVer vv) <> "'"
| otherwise = text $ "Unable to find a download for " <> T.unpack (tVerToText tver)

instance HFErrorProject NoDownload where
eBase _ = 10
Expand Down
11 changes: 6 additions & 5 deletions lib/GHCup/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ testGHCVer ver addMakeArgs = do

dlInfo <-
preview (ix GHC % ix ver % viTestDL % _Just) dls
?? NoDownload
?? NoDownload (Just ver)

liftE $ testGHCBindist dlInfo ver addMakeArgs

Expand Down Expand Up @@ -260,7 +260,7 @@ fetchGHCSrc v mfp = do
GHCupInfo { _ghcupDownloads = dls } <- lift getGHCupInfo
dlInfo <-
preview (ix GHC % ix v % viSourceDL % _Just) dls
?? NoDownload
?? NoDownload (Just v)
liftE $ downloadCached' dlInfo Nothing mfp


Expand Down Expand Up @@ -827,9 +827,10 @@ compileGHC targetGhc crossTarget ov bstrap jobs mbuildConfig patches aargs build
lift $ logDebug $ "Requested to compile: " <> prettyVer ver <> " with " <> either prettyVer T.pack bstrap

-- download source tarball
let tver = mkTVer ver
dlInfo <-
preview (ix GHC % ix (mkTVer ver) % viSourceDL % _Just) dls
?? NoDownload
preview (ix GHC % ix tver % viSourceDL % _Just) dls
?? NoDownload (Just tver)
dl <- liftE $ downloadCached dlInfo Nothing

-- unpack
Expand Down Expand Up @@ -1303,7 +1304,7 @@ compileGHC targetGhc crossTarget ov bstrap jobs mbuildConfig patches aargs build

bghc = case bstrap of
Right g -> g
Left bver -> ("ghc-" <> (T.unpack . prettyVer $ bver) <> exeExt)
Left bver -> "ghc-" <> (T.unpack . prettyVer $ bver) <> exeExt



Expand Down
2 changes: 1 addition & 1 deletion lib/GHCup/HLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ compileHLS targetHLS ghcs jobs ov installDir cabalProject cabalProjectLocal upda
-- download source tarball
dlInfo <-
preview (ix HLS % ix (mkTVer tver) % viSourceDL % _Just) dls
?? NoDownload
?? NoDownload (Just (mkTVer tver))
dl <- liftE $ downloadCached dlInfo Nothing

-- unpack
Expand Down
2 changes: 1 addition & 1 deletion lib/GHCup/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ ensureGlobalTools
(GHCupInfo _ _ gTools) <- lift getGHCupInfo
dirs <- lift getDirs
shimDownload <- liftE $ lE @_ @'[NoDownload]
$ maybe (Left NoDownload) Right $ Map.lookup ShimGen gTools
$ maybe (Left (NoDownload Nothing)) Right $ Map.lookup ShimGen gTools
let dl = downloadCached' shimDownload (Just "gs.exe") Nothing
void $ (\DigestError{} -> do
lift $ logWarn "Digest doesn't match, redownloading gs.exe..."
Expand Down

0 comments on commit b46537f

Please sign in to comment.