From 274f94ce9ae7e6d7ca11dae1dcc8c0d72ed17ddf Mon Sep 17 00:00:00 2001
From: Fabian Kirchner <kirchner@posteo.de>
Date: Sat, 14 Oct 2023 14:50:29 +0200
Subject: refactor: move and hide exceptions from outside module

---
 app/History.hs | 44 ++++++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 20 deletions(-)

(limited to 'app')

diff --git a/app/History.hs b/app/History.hs
index 09d66e1..252380d 100644
--- a/app/History.hs
+++ b/app/History.hs
@@ -1,7 +1,7 @@
 {-# LANGUAGE OverloadedRecordDot #-}
 {-# LANGUAGE OverloadedStrings #-}
 
-module History (getIssues, InvalidTreeGrepperResult (..), UnknownFileExtension (..), listIssues) where
+module History (getIssues, listIssues) where
 
 import Control.Exception (Exception, catch, handle, throw)
 import Data.Aeson (eitherDecode)
@@ -28,20 +28,6 @@ import TreeGrepper.Result qualified as G
 import Prelude hiding (id, lines)
 import Prelude qualified as Prelude
 
-data UnknownFileExtension = UnknownFileExtension
-  { extension :: String
-  }
-  deriving (Show)
-
-instance Exception UnknownFileExtension
-
-data InvalidTreeGrepperResult = InvalidTreeGrepperResult
-  { error :: String
-  }
-  deriving (Show)
-
-instance Exception InvalidTreeGrepperResult
-
 listIssues :: [Filter] -> [FilePath] -> IO [Issue]
 listIssues filters paths = do
   commits <- getCommits
@@ -77,7 +63,7 @@ listIssuesCurrent :: [FilePath] -> IO [Issue]
 listIssuesCurrent paths = do
   worktree <- getCurrentDirectory
   files <- getFiles worktree paths
-  concat <$> (catch (getIssuesPar worktree files) (\(InvalidTreeGrepperResult e) -> die e))
+  concat <$> (catch (getIssuesPar worktree files) dieOfInvalidTreeGrepperResult)
 
 listIssuesOf :: Text -> IO [Issue]
 listIssuesOf commit = do
@@ -87,10 +73,7 @@ listIssuesOf commit = do
       sh_ (fromString (printf "git worktree add --detach %s %s" (quote worktree) (quote (unpack commit))))
       pure worktree
     files <- getFilesChanged worktree
-    concat <$> catch (getIssuesPar worktree files) (\(InvalidTreeGrepperResult e) -> die e)
-
-forgetGetIssuesExceptions :: UnknownFileExtension -> IO [a]
-forgetGetIssuesExceptions _ = pure []
+    concat <$> catch (getIssuesPar worktree files) (dieOfInvalidTreeGrepperResult)
 
 getFiles :: FilePath -> [String] -> IO [FilePath]
 getFiles cwd paths =
@@ -118,6 +101,27 @@ getIssuesPar :: FilePath -> [FilePath] -> IO [[Issue]]
 getIssuesPar worktree =
   parMapM (handle forgetGetIssuesExceptions . getIssues worktree)
 
+data UnknownFileExtension = UnknownFileExtension
+  { extension :: String
+  }
+  deriving (Show)
+
+instance Exception UnknownFileExtension
+
+forgetGetIssuesExceptions :: UnknownFileExtension -> IO [a]
+forgetGetIssuesExceptions _ = pure []
+
+data InvalidTreeGrepperResult = InvalidTreeGrepperResult
+  { error :: String
+  }
+  deriving (Show)
+
+instance Exception InvalidTreeGrepperResult
+
+dieOfInvalidTreeGrepperResult :: InvalidTreeGrepperResult -> IO a
+dieOfInvalidTreeGrepperResult (InvalidTreeGrepperResult e) =
+  die e
+
 getIssues :: FilePath -> FilePath -> IO [Issue]
 getIssues cwd filename = do
   let extension = takeExtension filename
-- 
cgit v1.2.3