module Trace.Hpc.Codecov.Exception
(
HpcCodecovError(..)
, withBriefUsageOnError
) where
import Control.Exception (Exception (..), handle)
import System.Environment (getProgName)
import System.Exit (exitFailure)
withBriefUsageOnError :: IO a
-> IO a
withBriefUsageOnError :: forall a. IO a -> IO a
withBriefUsageOnError = forall e a. Exception e => (e -> IO a) -> IO a -> IO a
handle forall a. HpcCodecovError -> IO a
handler
where
handler :: HpcCodecovError -> IO a
handler :: forall a. HpcCodecovError -> IO a
handler HpcCodecovError
e =
do FilePath -> IO ()
putStr (FilePath
"Error: " forall a. [a] -> [a] -> [a]
++ forall e. Exception e => e -> FilePath
displayException HpcCodecovError
e)
FilePath
name <- IO FilePath
getProgName
FilePath -> IO ()
putStrLn (FilePath
"Run '" forall a. [a] -> [a] -> [a]
++ FilePath
name forall a. [a] -> [a] -> [a]
++ FilePath
" --help' for usage.")
forall a. IO a
exitFailure
data HpcCodecovError
= NoTarget
| TixNotFound FilePath
| MixNotFound FilePath [FilePath]
| SrcNotFound FilePath [FilePath]
| InvalidBuildTool String
| InvalidFormat String
| TestSuiteNotFound String
| InvalidArgs [String]
deriving (Int -> HpcCodecovError -> ShowS
[HpcCodecovError] -> ShowS
HpcCodecovError -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [HpcCodecovError] -> ShowS
$cshowList :: [HpcCodecovError] -> ShowS
show :: HpcCodecovError -> FilePath
$cshow :: HpcCodecovError -> FilePath
showsPrec :: Int -> HpcCodecovError -> ShowS
$cshowsPrec :: Int -> HpcCodecovError -> ShowS
Show)
instance Exception HpcCodecovError where
displayException :: HpcCodecovError -> FilePath
displayException = HpcCodecovError -> FilePath
hpcCodecovErrorMessage
hpcCodecovErrorMessage :: HpcCodecovError -> String
hpcCodecovErrorMessage :: HpcCodecovError -> FilePath
hpcCodecovErrorMessage HpcCodecovError
e =
case HpcCodecovError
e of
HpcCodecovError
NoTarget -> FilePath
"no TARGET was given\n"
TixNotFound FilePath
tix -> FilePath
"cannot find tix: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show FilePath
tix forall a. [a] -> [a] -> [a]
++ FilePath
"\n"
MixNotFound FilePath
mix [FilePath]
locs -> FilePath -> FilePath -> [FilePath] -> FilePath
searchedLocations FilePath
"mix" FilePath
mix [FilePath]
locs
SrcNotFound FilePath
src [FilePath]
locs -> FilePath -> FilePath -> [FilePath] -> FilePath
searchedLocations FilePath
"src" FilePath
src [FilePath]
locs
InvalidBuildTool FilePath
tool-> FilePath
"invalid build tool: `" forall a. [a] -> [a] -> [a]
++ FilePath
tool forall a. [a] -> [a] -> [a]
++ FilePath
"'\n"
InvalidFormat FilePath
fmt -> FilePath
"invalid format: `" forall a. [a] -> [a] -> [a]
++ FilePath
fmt forall a. [a] -> [a] -> [a]
++ FilePath
"'\n"
TestSuiteNotFound FilePath
name ->
FilePath
"cannot find tix for test suite: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show FilePath
name forall a. [a] -> [a] -> [a]
++ FilePath
"\n"
InvalidArgs [FilePath]
msgs ->
case [FilePath]
msgs of
[FilePath
x] -> FilePath
x
[FilePath]
_ -> Char
'\n' forall a. a -> [a] -> [a]
: forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (FilePath
" - " forall a. [a] -> [a] -> [a]
++) [FilePath]
msgs
searchedLocations :: String -> FilePath -> [FilePath] -> String
searchedLocations :: FilePath -> FilePath -> [FilePath] -> FilePath
searchedLocations FilePath
what FilePath
path [FilePath]
locs =
FilePath
"cannot find " forall a. [a] -> [a] -> [a]
++ FilePath
what forall a. [a] -> [a] -> [a]
++ FilePath
": " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show FilePath
path forall a. [a] -> [a] -> [a]
++ FilePath
locs'
where
locs' :: FilePath
locs' =
case [FilePath]
locs of
[FilePath
_] -> ShowS
searched FilePath
""
[FilePath]
_ -> ShowS
searched FilePath
"s"
searched :: ShowS
searched FilePath
post =
FilePath
"\nsearched location" forall a. [a] -> [a] -> [a]
++ FilePath
post forall a. [a] -> [a] -> [a]
++ FilePath
":\n" forall a. [a] -> [a] -> [a]
++
[FilePath] -> FilePath
unlines (forall a b. (a -> b) -> [a] -> [b]
map (FilePath
" " forall a. [a] -> [a] -> [a]
++) [FilePath]
locs)