diff options
author | Fabian Kirchner <kirchner@posteo.de> | 2023-10-14 14:50:29 +0200 |
---|---|---|
committer | Fabian Kirchner <kirchner@posteo.de> | 2023-10-14 14:50:29 +0200 |
commit | 274f94ce9ae7e6d7ca11dae1dcc8c0d72ed17ddf (patch) | |
tree | 7a53f34c2c6ae2c78cac6e167380cc086fa4726e /app | |
parent | 5ebbe1ebeb31d3ac62705a7b572b93b9c09897af (diff) |
refactor: move and hide exceptions from outside module
Diffstat (limited to 'app')
-rw-r--r-- | app/History.hs | 44 |
1 files changed, 24 insertions, 20 deletions
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 |