aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2019-01-27 18:52:25 +0100
committertv <tv@krebsco.de>2019-01-27 18:52:25 +0100
commit4d85ce5584c5bc69b402b7d3b94c623f37ea69f5 (patch)
treeeb1b5b01b521b7d8c695384f3e731413a0f5689a
parent32ddebc0309a73c50e0f1974b4f9435fce3f86c9 (diff)
src: replace all undefined with typeMismatch
-rw-r--r--src/Data/ByteString/Char8/Extended.hs7
-rw-r--r--src/Reaktor/Internal.hs3
-rw-r--r--src/Reaktor/Plugins/Register.hs5
-rw-r--r--src/Reaktor/Plugins/System/Internal.hs10
4 files changed, 15 insertions, 10 deletions
diff --git a/src/Data/ByteString/Char8/Extended.hs b/src/Data/ByteString/Char8/Extended.hs
index ca0c44a..8bf76c7 100644
--- a/src/Data/ByteString/Char8/Extended.hs
+++ b/src/Data/ByteString/Char8/Extended.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE LambdaCase #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.ByteString.Char8.Extended
( module Data.ByteString.Char8
@@ -5,14 +6,16 @@ module Data.ByteString.Char8.Extended
) where
import Data.Aeson
+import Data.Aeson.Types (typeMismatch)
import Data.ByteString.Char8
import Data.Text.Encoding (encodeUtf8)
import Prelude hiding (show)
import qualified Prelude
instance FromJSON ByteString where
- parseJSON (String t) = pure (encodeUtf8 t)
- parseJSON _ = pure undefined
+ parseJSON = \case
+ String t -> pure (encodeUtf8 t)
+ invalid -> typeMismatch "ByteString" invalid
instance FromJSONKey ByteString where
fromJSONKey = FromJSONKeyText encodeUtf8
diff --git a/src/Reaktor/Internal.hs b/src/Reaktor/Internal.hs
index 09dd723..66e00af 100644
--- a/src/Reaktor/Internal.hs
+++ b/src/Reaktor/Internal.hs
@@ -6,6 +6,7 @@ module Reaktor.Internal where
import Prelude.Extended
import Blessings
import Data.Aeson
+import Data.Aeson.Types (typeMismatch)
import Data.String.Conversions (convertString)
import qualified Data.Text as T
import Network.Socket as Exports (HostName,ServiceName)
@@ -47,7 +48,7 @@ instance FromJSON Config where
cLogHandle <- pure (cLogHandle def)
cLogTime <- v .:? "logTime" .!= cLogTime def
pure Config{..}
- _ -> undefined
+ invalid -> typeMismatch "Config" invalid
where
tlsPort :: ServiceName
tlsPort = "6697"
diff --git a/src/Reaktor/Plugins/Register.hs b/src/Reaktor/Plugins/Register.hs
index 979e4ba..dcd130e 100644
--- a/src/Reaktor/Plugins/Register.hs
+++ b/src/Reaktor/Plugins/Register.hs
@@ -6,6 +6,7 @@ module Reaktor.Plugins.Register where
import Blessings
import Data.Aeson
+import Data.Aeson.Types (typeMismatch)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Prelude.Extended
@@ -23,7 +24,7 @@ instance FromJSON ConfigNickServ where
ConfigNickServ
<$> v .: "passFile"
<*> v .:? "prefix" .!= "NickServ!NickServ@services."
- _ -> undefined
+ invalid -> typeMismatch "ConfigNickServ" invalid
data Config = Config
{ cNick :: Maybe Text
@@ -43,7 +44,7 @@ instance FromJSON Config where
cChannels <- v .:? "channels" .!= []
cNickServ <- v .:? "NickServ" .!= cNickServ def
pure Config{..}
- _ -> undefined
+ invalid -> typeMismatch "Config" invalid
new :: Config -> Actions -> IO (Message -> IO ())
new Config{..} Actions{..} = do
diff --git a/src/Reaktor/Plugins/System/Internal.hs b/src/Reaktor/Plugins/System/Internal.hs
index 78c8802..e4356df 100644
--- a/src/Reaktor/Plugins/System/Internal.hs
+++ b/src/Reaktor/Plugins/System/Internal.hs
@@ -4,6 +4,7 @@ module Reaktor.Plugins.System.Internal where
import Prelude.Extended
import Data.Aeson
+import Data.Aeson.Types (typeMismatch)
import Reaktor ()
import qualified Reaktor.IRC as IRC
import Text.Regex.PCRE.Light (Regex)
@@ -27,7 +28,7 @@ instance FromJSON Activate where
String "always" -> pure Always
String "match" -> pure Match
String "query" -> pure Query
- _ -> undefined
+ invalid -> typeMismatch "Activate" invalid
data Config = Config
{ cWorkDir :: Maybe FilePath
@@ -44,7 +45,7 @@ instance FromJSON Config where
Config
<$> v .:? "workdir"
<*> v .:? "hooks" .!= mempty
- _ -> undefined
+ invalid -> typeMismatch "Config" invalid
data Hook = Hook
{ hActivate :: Activate
@@ -68,7 +69,7 @@ instance FromJSON Hook where
<*> v .:? "workdir"
<*> v .:? "commands" .!= mempty
<*> (fmap (*1000000) <$> v .:? "timeoutSec" .!= Just 10)
- _ -> undefined
+ invalid -> typeMismatch "Hook" invalid
data SystemCommand = SystemCommand
@@ -85,5 +86,4 @@ instance FromJSON SystemCommand where
<$> v .: "filename"
<*> v .:? "workdir"
<*> v .:? "env"
- _ -> undefined
-
+ invalid -> typeMismatch "SystemCommand" invalid