Skip to content

Commit

Permalink
Improve error reporting from the executable
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Aug 27, 2024
1 parent 2112309 commit c47b109
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ mkInputs isCmpRequired cabalFile origContents args = do
x :| (y : ys)
| Right c <- mkCmp (Just x) ->
(c,) <$> mkDeps (y :| ys)
| isCmpRequired -> Left $ "Target component '" ++ x ++ "' is not found"
_ ->
if isCmpRequired
then Left "Component is required"
then Left "Target component is required"
else (,) <$> mkCmp Nothing <*> mkDeps args
pure $ Input cabalFile packDescr (Config origContents fields cmp deps)

Expand All @@ -176,12 +177,12 @@ disambiguateInputs mProjectFile inputs = case inputs' of
Just projFn -> "No Cabal files are found in " ++ projFn
(errs, []) ->
Left $
"No matching targets found amongst: "
++ L.intercalate ", " (map fst errs)
L.intercalate "\n" $
map (\(fn, err) -> "Cannot add a dependency to " ++ fn ++ " because: " ++ err) errs
(_, [inp]) -> pure $ snd inp
(_, _inps) ->
Left
"Target component is ambiguous, please specify it as package:type:component. See https://cabal.readthedocs.io/en/latest/cabal-commands.html#target-forms for reference"
"Cannot add a dependency, because target component is ambiguous. Please specify it as package:type:component. See https://cabal.readthedocs.io/en/latest/cabal-commands.html#target-forms for reference"
where
inputs' = partitionEithers $ map (\(fn, e) -> bimap (fn,) (fn,) e) inputs

Expand All @@ -206,7 +207,18 @@ main = do
(\(fn, cnt) -> (fn, mkInputs isCmpRequired fn cnt rcnfArgs))
cabalFilesAndContent

input <- either (const $ either die pure $ getInput True) pure (getInput False)
input <- case getInput False of
Right i -> pure i
Left errFalse -> case rcnfArgs of
_ :| [] -> die errFalse
_ -> case getInput True of
Right i -> pure i
Left errTrue ->
die $
"If the first argument is interpreted as a dependency:\n"
++ errFalse
++ "\n\nIf the first argument is interpreted as a target component:\n"
++ errTrue

let Input cabalFile origPackDescr cnf = input

Expand Down

0 comments on commit c47b109

Please sign in to comment.