From 4d85ce5584c5bc69b402b7d3b94c623f37ea69f5 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 27 Jan 2019 18:52:25 +0100 Subject: src: replace all undefined with typeMismatch --- src/Data/ByteString/Char8/Extended.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/Data/ByteString') 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 -- cgit v1.2.3