diff options
-rw-r--r-- | src/Lib.hs | 10 | ||||
-rw-r--r-- | src/Plugin/GitHubCommit.hs | 11 |
2 files changed, 16 insertions, 5 deletions
@@ -2,6 +2,11 @@ module Lib ( someFunc ) where +import Control.Exception (catch) +-- import System.Environment +-- import System.IO +-- import System.IO.Error + import Database.SQLite.Simple import Message @@ -17,5 +22,8 @@ someFunc = do Just plugin = matchPlugin message dbConn <- open "db/sorbot_development.sqlite3" response <- performPlugin plugin message dbConn - putStrLn response + putStrLn response `catch` handleError close dbConn + +handleError :: IOError -> IO () +handleError err = putStrLn $ show err diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs index cac74a4..8c11a12 100644 --- a/src/Plugin/GitHubCommit.hs +++ b/src/Plugin/GitHubCommit.hs @@ -24,12 +24,15 @@ gitHubCommitAction message dbConn = do \ LIMIT 1" (Only (M.channel message)) :: IO [RepoUrlRow] - return $ response rs + -- return $ response rs + respond rs where - response [] = "" - response ((RepoUrlRow r):rs) = - r ++ "/commits/" ++ M.text message =~ matchRegex gitHubCommit + respond [] = fail "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 type Id = Int |