aboutsummaryrefslogtreecommitdiffstats
path: root/src/Plugin
diff options
context:
space:
mode:
authorTeddy Wing2017-08-10 23:54:57 +0200
committerTeddy Wing2017-08-10 23:54:57 +0200
commitccf11b5467b2f41690390a20bc50a02c006be3f0 (patch)
tree376eff572bd78446f466c15672ab09df3e421e2e /src/Plugin
parent465f32c216bd9a9bd695f0a2f0f3a08369c51e9a (diff)
downloadsorbot-ccf11b5467b2f41690390a20bc50a02c006be3f0.tar.bz2
gitHubCommitAction: Get error handling to work using `Either`
Get rid of the `fail` and use an `Either` for error handling instead. This allows us to send back the response string like before, but provide an additional error message when no data comes back from the database query. Remove the old error handling code I had tried to set up previously.
Diffstat (limited to 'src/Plugin')
-rw-r--r--src/Plugin/Base.hs2
-rw-r--r--src/Plugin/GitHubCommit.hs11
2 files changed, 5 insertions, 8 deletions
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