Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cabal Error Refactor #9018

Merged
merged 33 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4a438ba
I have added a function "dieWithException" which will replace the die…
SuganyaAK Jun 12, 2023
fe970bc
Codebase is formatted with fourmolu and compiled without warnings.
SuganyaAK Jun 13, 2023
722d778
Enabled fourmolu action
SuganyaAK Jun 13, 2023
574bf67
Running fourmolu through github action as the previous ones failed.
SuganyaAK Jun 14, 2023
5663f3b
Function `exceptionWithMetadata` and constructors for each exception …
SuganyaAK Jun 23, 2023
7bdb74d
I have added a function "dieWithException" which will replace the die…
SuganyaAK Jun 12, 2023
570d1e5
Codebase is formatted with fourmolu and compiled without warnings.
SuganyaAK Jun 13, 2023
6842366
Enabled fourmolu action
SuganyaAK Jun 13, 2023
3f11d92
Running fourmolu through github action as the previous ones failed.
SuganyaAK Jun 14, 2023
9e6a92c
Function `exceptionWithMetadata` and constructors for each exception …
SuganyaAK Jun 23, 2023
efac6a4
Updated changelog
SuganyaAK Jun 23, 2023
56a58ac
Merge branch 'Cabal-Error-Refactor' of https://github.com/SuganyaAK/c…
SuganyaAK Jun 23, 2023
9c90d0b
PatternMatching cases of diewithexception and displayexception reduced
SuganyaAK Jun 23, 2023
56e4473
Delete fourmolu.yaml
SuganyaAK Jun 23, 2023
b47370b
Delete settings.json
SuganyaAK Jun 23, 2023
0e7f15a
Replaced die' calls for modules srcDist.hs and HcPkg.hs
SuganyaAK Jun 26, 2023
a1365df
Merge branch 'Cabal-Error-Refactor' of https://github.com/SuganyaAK/c…
SuganyaAK Jun 26, 2023
7e017ba
Replaced die' calls in modules `build.hs`,`Haddock.hs` and `Program.hs`
SuganyaAK Jun 29, 2023
fb3275a
Replaced die' calls in modules `Build.hs`, `Haddock.hs` and `Program.hs`
SuganyaAK Jun 29, 2023
6a4a886
Replaced die' calls in modules `GHCJS.hs`, `HaskellSuite.hs` and `Bui…
SuganyaAK Jul 4, 2023
1e0bbef
Merge branch 'master' into Cabal-Error-Refactor
SuganyaAK Jul 4, 2023
fe51fb1
Formatted the codebase with Fourmolu
SuganyaAK Jul 7, 2023
d47b8ae
Accepted the new output with error codes and adding the file relevant…
SuganyaAK Jul 7, 2023
2fe47db
Changes in `Utils.hs` and `Errors.hs` to reflect the new error codes
SuganyaAK Jul 7, 2023
2ad952d
Keeping rip intact
SuganyaAK Jul 8, 2023
bbc63bc
test changes
gbaz Jul 12, 2023
cf5a38f
CallStack unmarked from the error output
SuganyaAK Jul 14, 2023
972eb33
callstack unmarked from output
SuganyaAK Jul 14, 2023
12a5846
unmarked callstack in test output
gbaz Jul 14, 2023
2fd3503
Format the codebase with fourmolu
SuganyaAK Jul 15, 2023
9aa458c
Changed to Error identifier to "Cabal-"
SuganyaAK Jul 16, 2023
2dc8828
Updated Constructors as per review comments
SuganyaAK Jul 16, 2023
4fd1225
Rectifying Hlint warning
SuganyaAK Jul 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: fourmolu
on: push
jobs:
format:
runs-on: ubuntu-latest
steps:
# Note that you must checkout your code before running haskell-actions/run-fourmolu
- uses: actions/checkout@v2
- uses: haskell-actions/run-fourmolu@v9
with:
version: "0.12.0.0"
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"haskell.formattingProvider": "fourmolu"
}
1 change: 1 addition & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ library
Distribution.Simple.Command
Distribution.Simple.Compiler
Distribution.Simple.Configure
Distribution.Simple.Errors
Distribution.Simple.Flag
Distribution.Simple.GHC
Distribution.Simple.GHCJS
Expand Down
24 changes: 10 additions & 14 deletions Cabal/src/Distribution/Simple/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ import Distribution.Simple.InstallDirs
import qualified Distribution.Simple.LocalBuildInfo as LBI
import Distribution.Simple.Setup.Benchmark
import Distribution.Simple.UserHooks
import Distribution.Simple.Utils
import Distribution.Simple.Utils

import Distribution.Types.UnqualComponentName

import System.Directory (doesFileExist)
import System.FilePath ((<.>), (</>))
import Distribution.Simple.Errors

-- | Perform the \"@.\/setup bench@\" action.
bench
Expand Down Expand Up @@ -65,11 +67,8 @@ bench args pkg_descr lbi flags = do
-- Check that the benchmark executable exists.
exists <- doesFileExist cmd
unless exists $
die' verbosity $
"Could not find benchmark program \""
++ cmd
++ "\". Did you build the package first?"

dieWithException verbosity $ NoBenchMarkProgram cmd

notice verbosity $ startMessage name
-- This will redirect the child process
-- stdout/stderr to the parent process.
Expand All @@ -92,9 +91,8 @@ bench args pkg_descr lbi flags = do
exitSuccess

when (PD.hasBenchmarks pkg_descr && null enabledBenchmarks) $
die' verbosity $
"No benchmarks enabled. Did you remember to configure with "
++ "\'--enable-benchmarks\'?"
dieWithException verbosity EnableBenchMark


bmsToRun <- case benchmarkNames of
[] -> return enabledBenchmarks
Expand All @@ -106,11 +104,9 @@ bench args pkg_descr lbi flags = do
Just t -> return t
_
| mkUnqualComponentName bmName `elem` allNames ->
die' verbosity $
"Package configured with benchmark "
++ bmName
++ " disabled."
| otherwise -> die' verbosity $ "no such benchmark: " ++ bmName
dieWithException verbosity $ BenchMarkNameDisable bmName
| otherwise -> dieWithException verbosity $ NoBenchMark bmName


let totalBenchmarks = length bmsToRun
notice verbosity $ "Running " ++ show totalBenchmarks ++ " benchmarks..."
Expand Down
61 changes: 61 additions & 0 deletions Cabal/src/Distribution/Simple/Errors.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-----------------------------------------------------------------------------

-- Module : Distribution.Simple.Errors
-- Copyright :
-- License :
--
-- Maintainer :
-- Portability :
--
-- A collection of Exception Types used throughout
--the rest of the Cabal library package

module Distribution.Simple.Errors
(
CabalException (..)
,exceptionCode
,exceptionMessage
) where

import Distribution.Compat.Prelude
import Distribution.Compiler
import Distribution.Pretty
( prettyShow
)


-- Types representing exceptions thrown by functions in all the modules of Cabal Package
data CabalException = NoBenchMarkProgram FilePath
| EnableBenchMark
| BenchMarkNameDisable String
| NoBenchMark String
| NoLibraryFound
| CompilerNotInstalled CompilerFlavor
| CantFindIncludeFile String
| SourceDistException String
deriving (Show,Typeable)

exceptionCode :: CabalException -> Int
exceptionCode e = case e of
(NoBenchMarkProgram _) -> 1678
ulysses4ever marked this conversation as resolved.
Show resolved Hide resolved
EnableBenchMark -> 1453
(BenchMarkNameDisable _) -> 2781
(NoBenchMark _) -> 1654
NoLibraryFound -> 2546
(CompilerNotInstalled _) -> 7465
(CantFindIncludeFile _) -> 3876
(SourceDistException _ ) -> 3245

exceptionMessage :: CabalException -> String
exceptionMessage e = case e of
NoBenchMarkProgram cmd -> "Could not find benchmark program \"" ++ cmd ++ "\". Did you build the package first?"
EnableBenchMark -> "No benchmarks enabled. Did you remember to configure with " ++ "\'--enable-benchmarks\'?"
BenchMarkNameDisable bmName -> "Package configured with benchmark " ++ bmName ++ " disabled."
NoBenchMark bmName -> "no such benchmark: " ++ bmName
NoLibraryFound -> "No executables and no library found. Nothing to do."
CompilerNotInstalled compilerFlavor -> "installing with " ++ prettyShow compilerFlavor ++ "is not implemented"
CantFindIncludeFile file -> "can't find include file " ++ file
(SourceDistException _ ) -> "3245"
ulysses4ever marked this conversation as resolved.
Show resolved Hide resolved



37 changes: 22 additions & 15 deletions Cabal/src/Distribution/Simple/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ import Distribution.Simple.Setup.Haddock
( HaddockTarget (ForDevelopment)
)
import Distribution.Simple.Utils

( createDirectoryIfMissingVerbose
, die'
, dieWithException
, info
, installDirectoryContents
, installOrdinaryFile
Expand All @@ -65,6 +66,7 @@ import qualified Distribution.Simple.GHC as GHC
import qualified Distribution.Simple.GHCJS as GHCJS
import qualified Distribution.Simple.HaskellSuite as HaskellSuite
import qualified Distribution.Simple.UHC as UHC
import Distribution.Simple.Errors

import System.Directory
( doesDirectoryExist
Expand Down Expand Up @@ -113,7 +115,8 @@ install pkg_descr lbi flags = do

checkHasLibsOrExes =
unless (hasLibs pkg_descr || hasForeignLibs pkg_descr || hasExes pkg_descr) $
die' verbosity "No executables and no library found. Nothing to do."
dieWithException verbosity NoLibraryFound
-- InstallException "No executables and no library found. Nothing to do."

-- | Copy package global files.
copyPackage
Expand Down Expand Up @@ -223,10 +226,12 @@ copyComponent verbosity pkg_descr lbi (CLib lib) clbi copydest = do
lib
clbi
_ ->
die' verbosity $
"installing with "
++ prettyShow (compilerFlavor (compiler lbi))
++ " is not implemented"
dieWithException verbosity $ CompilerNotInstalled (compilerFlavor (compiler lbi))
-- InstallException
-- ("installing with "
-- ++ prettyShow (compilerFlavor (compiler lbi))
-- ++ " is not implemented")

copyComponent verbosity pkg_descr lbi (CFLib flib) clbi copydest = do
let InstallDirs
{ flibdir = flibPref
Expand All @@ -241,10 +246,11 @@ copyComponent verbosity pkg_descr lbi (CFLib flib) clbi copydest = do
GHC -> GHC.installFLib verbosity lbi flibPref buildPref pkg_descr flib
GHCJS -> GHCJS.installFLib verbosity lbi flibPref buildPref pkg_descr flib
_ ->
die' verbosity $
"installing foreign lib with "
++ prettyShow (compilerFlavor (compiler lbi))
++ " is not implemented"
dieWithException verbosity $ CompilerNotInstalled (compilerFlavor (compiler lbi))
-- ("installing foreign lib with "
-- ++ prettyShow (compilerFlavor (compiler lbi))
-- ++ " is not implemented")

copyComponent verbosity pkg_descr lbi (CExe exe) clbi copydest = do
let installDirs = absoluteComponentInstallDirs pkg_descr lbi (componentUnitId clbi) copydest
-- the installers know how to find the actual location of the
Expand Down Expand Up @@ -279,10 +285,10 @@ copyComponent verbosity pkg_descr lbi (CExe exe) clbi copydest = do
UHC -> return ()
HaskellSuite{} -> return ()
_ ->
die' verbosity $
"installing with "
++ prettyShow (compilerFlavor (compiler lbi))
++ " is not implemented"
dieWithException verbosity $ CompilerNotInstalled (compilerFlavor (compiler lbi))
-- ("installing with "
-- ++ prettyShow (compilerFlavor (compiler lbi))
-- ++ " is not implemented")

-- Nothing to do for benchmark/testsuite
copyComponent _ _ _ (CBench _) _ _ = return ()
Expand Down Expand Up @@ -322,7 +328,8 @@ installIncludeFiles verbosity libBi lbi buildPref destIncludeDir = do
]
where
baseDir lbi' = fromMaybe "" (takeDirectory <$> cabalFilePath lbi')
findInc [] file = die' verbosity ("can't find include file " ++ file)
findInc [] file = dieWithException verbosity $ CantFindIncludeFile file
-- InstallException ("can't find include file " ++ file)
findInc (dir : dirs) file = do
let path = dir </> file
exists <- doesFileExist path
Expand Down
39 changes: 20 additions & 19 deletions Cabal/src/Distribution/Simple/SrcDist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import Data.Time (UTCTime, getCurrentTime, toGregorian, utctDay)
import System.Directory (doesFileExist)
import System.FilePath (dropExtension, isRelative, (<.>), (</>))
import System.IO (IOMode (WriteMode), hPutStrLn, withFile)
import Distribution.Simple.Errors

-- | Create a source distribution.
sdist
Expand Down Expand Up @@ -165,9 +166,9 @@ listPackageSourcesWithDie
-- ^ extra preprocessors (include suffixes)
-> IO [FilePath]
-- ^ relative paths
listPackageSourcesWithDie verbosity rip cwd pkg_descr0 pps = do
listPackageSourcesWithDie verbosity _rip cwd pkg_descr0 pps = do
-- Call helpers that actually do all work.
listPackageSources' verbosity rip cwd pkg_descr pps
listPackageSources' verbosity _rip cwd pkg_descr pps
where
pkg_descr = filterAutogenModules pkg_descr0

Expand All @@ -187,7 +188,7 @@ listPackageSources'
-- ^ extra preprocessors (include suffixes)
-> IO [FilePath]
-- ^ relative paths
listPackageSources' verbosity rip cwd pkg_descr pps =
listPackageSources' verbosity _rip cwd pkg_descr pps =
fmap concat . sequenceA $
[ -- Library sources.
fmap concat
Expand All @@ -197,19 +198,19 @@ listPackageSources' verbosity rip cwd pkg_descr pps =
, signatures = sigs
, libBuildInfo = libBi
} ->
allSourcesBuildInfo verbosity rip cwd libBi pps (modules ++ sigs)
allSourcesBuildInfo verbosity _rip cwd libBi pps (modules ++ sigs)
, -- Executables sources.
fmap concat
. withAllExe
$ \Executable{modulePath = mainPath, buildInfo = exeBi} -> do
biSrcs <- allSourcesBuildInfo verbosity rip cwd exeBi pps []
biSrcs <- allSourcesBuildInfo verbosity _rip cwd exeBi pps []
mainSrc <- findMainExeFile verbosity cwd exeBi pps mainPath
return (mainSrc : biSrcs)
, -- Foreign library sources
fmap concat
. withAllFLib
$ \flib@(ForeignLib{foreignLibBuildInfo = flibBi}) -> do
biSrcs <- allSourcesBuildInfo verbosity rip cwd flibBi pps []
biSrcs <- allSourcesBuildInfo verbosity _rip cwd flibBi pps []
defFiles <-
traverse
(findModDefFile verbosity cwd flibBi pps)
Expand All @@ -222,25 +223,25 @@ listPackageSources' verbosity rip cwd pkg_descr pps =
let bi = testBuildInfo t
case testInterface t of
TestSuiteExeV10 _ mainPath -> do
biSrcs <- allSourcesBuildInfo verbosity rip cwd bi pps []
biSrcs <- allSourcesBuildInfo verbosity _rip cwd bi pps []
srcMainFile <- findMainExeFile verbosity cwd bi pps mainPath
return (srcMainFile : biSrcs)
TestSuiteLibV09 _ m ->
allSourcesBuildInfo verbosity rip cwd bi pps [m]
allSourcesBuildInfo verbosity _rip cwd bi pps [m]
TestSuiteUnsupported tp ->
rip verbosity $ "Unsupported test suite type: " ++ show tp
dieWithException verbosity $ SourceDistException ("Unsupported test suite type: " ++ show tp)
, -- Benchmarks sources.
fmap concat
. withAllBenchmark
$ \bm -> do
let bi = benchmarkBuildInfo bm
case benchmarkInterface bm of
BenchmarkExeV10 _ mainPath -> do
biSrcs <- allSourcesBuildInfo verbosity rip cwd bi pps []
biSrcs <- allSourcesBuildInfo verbosity _rip cwd bi pps []
srcMainFile <- findMainExeFile verbosity cwd bi pps mainPath
return (srcMainFile : biSrcs)
BenchmarkUnsupported tp ->
rip verbosity $ "Unsupported benchmark type: " ++ show tp
dieWithException verbosity $ SourceDistException ("Unsupported benchmark type: " ++ show tp)
, -- Data files.
fmap concat
. for (dataFiles pkg_descr)
Expand All @@ -249,15 +250,15 @@ listPackageSources' verbosity rip cwd pkg_descr pps =
srcDataDir
| null srcDataDirRaw = "."
| otherwise = srcDataDirRaw
matchDirFileGlobWithDie verbosity rip (specVersion pkg_descr) cwd (srcDataDir </> filename)
matchDirFileGlobWithDie verbosity _rip (specVersion pkg_descr) cwd (srcDataDir </> filename)
, -- Extra source files.
fmap concat . for (extraSrcFiles pkg_descr) $ \fpath ->
matchDirFileGlobWithDie verbosity rip (specVersion pkg_descr) cwd fpath
matchDirFileGlobWithDie verbosity _rip (specVersion pkg_descr) cwd fpath
, -- Extra doc files.
fmap concat
. for (extraDocFiles pkg_descr)
$ \filename ->
matchDirFileGlobWithDie verbosity rip (specVersion pkg_descr) cwd filename
matchDirFileGlobWithDie verbosity _rip (specVersion pkg_descr) cwd filename
, -- License file(s).
return (map getSymbolicPath $ licenseFiles pkg_descr)
, -- Install-include files, without autogen-include files
Expand Down Expand Up @@ -361,7 +362,7 @@ findModDefFile verbosity cwd flibBi _pps modDefPath =
-- @f@. Return the name of the file and the full path, or exit with error if
-- there's no such file.
findIncludeFile :: Verbosity -> FilePath -> [FilePath] -> String -> IO (String, FilePath)
findIncludeFile verbosity _ [] f = die' verbosity ("can't find include file " ++ f)
findIncludeFile verbosity _ [] f = dieWithException verbosity $ SourceDistException ("can't find include file " ++ f)
findIncludeFile verbosity cwd (d : ds) f = do
let path = (d </> f)
b <- doesFileExist (cwd </> path)
Expand Down Expand Up @@ -504,7 +505,7 @@ allSourcesBuildInfo
-> [ModuleName]
-- ^ Exposed modules
-> IO [FilePath]
allSourcesBuildInfo verbosity rip cwd bi pps modules = do
allSourcesBuildInfo verbosity _rip cwd bi pps modules = do
let searchDirs = map getSymbolicPath (hsSourceDirs bi)
sources <-
fmap concat $
Expand Down Expand Up @@ -542,13 +543,13 @@ allSourcesBuildInfo verbosity rip cwd bi pps modules = do

notFound :: ModuleName -> IO [FilePath]
notFound m =
rip verbosity $
"Could not find module: "
dieWithException verbosity $ SourceDistException
("Could not find module: "
++ prettyShow m
++ " with any suffix: "
++ show suffixes
++ ". If the module "
++ "is autogenerated it should be added to 'autogen-modules'."
++ "is autogenerated it should be added to 'autogen-modules'.")

-- | Note: must be called with the CWD set to the directory containing
-- the '.cabal' file.
Expand Down
Loading