diff options
| -rw-r--r-- | src/Lib.hs | 12 | ||||
| -rw-r--r-- | src/Plugin/Base.hs | 2 | ||||
| -rw-r--r-- | src/Plugin/GitHubCommit.hs | 11 | 
3 files changed, 8 insertions, 17 deletions
| @@ -2,11 +2,6 @@ module Lib      ( someFunc      ) where -import Control.Exception (catch) --- import System.Environment --- import System.IO --- import System.IO.Error -  import Database.SQLite.Simple  import Message @@ -22,8 +17,7 @@ someFunc = do          Just plugin = matchPlugin message      dbConn <- open "db/sorbot_development.sqlite3"      response <- performPlugin plugin message dbConn -    putStrLn response `catch` handleError +    case response of +        Left e  -> putStrLn e +        Right r -> putStrLn r      close dbConn - -handleError :: IOError -> IO () -handleError err = putStrLn $ show err diff --git a/src/Plugin/Base.hs b/src/Plugin/Base.hs index b752fd1..fe3a0f8 100644 --- a/src/Plugin/Base.hs +++ b/src/Plugin/Base.hs @@ -9,7 +9,7 @@ import Database.SQLite.Simple  import Message  -- TODO: Replace Connection with a type class -type PluginAction = Message -> Connection -> IO String +type PluginAction = Message -> Connection -> IO (Either String String)  data Plugin = Plugin      { matchRegex :: String diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs index 8c11a12..73b617c 100644 --- a/src/Plugin/GitHubCommit.hs +++ b/src/Plugin/GitHubCommit.hs @@ -24,15 +24,12 @@ gitHubCommitAction message dbConn = do          \ LIMIT 1"          (Only (M.channel message))          :: IO [RepoUrlRow] -    -- return $ response rs -    respond rs +    return $ respond rs    where -    respond []     = fail "I couldn't find a repo URL for this channel. \ -        \ Try `git remote set origin REPO_URL`" +    respond []     = Left "I couldn't find a repo URL for this channel. \ +        \Try `git remote set origin REPO_URL`"      respond ((RepoUrlRow r):rs) = -        return r ++ "/commits/" ++ M.text message =~ matchRegex gitHubCommit --- TODO: Make an Either type for plugins to return errors --- if empty query result, return an empty error, otherwise return the string +        Right $ r ++ "/commits/" ++ M.text message =~ matchRegex gitHubCommit  type Id = Int | 
