From 7d334c18f5edf68bbc9220cbabe92cda4a007dd7 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Tue, 28 Jul 2020 21:53:54 +0200 Subject: [PATCH] Don't stop TUI on subcommand failure --- app/ghcup/BrickMain.hs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/app/ghcup/BrickMain.hs b/app/ghcup/BrickMain.hs index a40cb1b..c3f526d 100644 --- a/app/ghcup/BrickMain.hs +++ b/app/ghcup/BrickMain.hs @@ -175,19 +175,18 @@ withIOAction :: (AppState -> (Int, ListResult) -> IO (Either String a)) withIOAction action as = case listSelectedElement (lr as) of Nothing -> continue as Just (ix, e) -> suspendAndResume $ do - r <- action as (ix, e) - case r of - Left err -> throwIO $ userError err - Right _ -> do - apps <- (fmap . fmap) - (\AppState {..} -> AppState { lr = listMoveTo ix lr, .. }) - $ getAppState Nothing (pfreq as) - case apps of - Right nas -> do - putStrLn "Press enter to continue" - _ <- getLine - pure nas - Left err -> throwIO $ userError err + action as (ix, e) >>= \case + Left err -> putStrLn $ ("Error: " <> err) + Right _ -> putStrLn "Success" + apps <- (fmap . fmap) + (\AppState {..} -> AppState { lr = listMoveTo ix lr, .. }) + $ getAppState Nothing (pfreq as) + case apps of + Right nas -> do + putStrLn "Press enter to continue" + _ <- getLine + pure nas + Left err -> throwIO $ userError err install' :: AppState -> (Int, ListResult) -> IO (Either String ())