From c4ca10b6ea7e36d7549519f053cfc3638c0bc325 Mon Sep 17 00:00:00 2001 From: Jake Lengyel Date: Mon, 23 Nov 2015 13:19:55 -0800 Subject: [PATCH] Add (de)serialization functions to most datasources Summary: Add serialization and deserialization functions to non-risk datasources that don't require special treatment (like CacheClient, etc), for use with D2628780 Reviewed By: simonmar Differential Revision: D2645436 fbshipit-source-id: 2777dbfbb11528bc079e2e82e88ebbdc880a8914 --- Haxl/Core/Exception.hs | 10 ++++++---- tests/TestTypes.hs | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Haxl/Core/Exception.hs b/Haxl/Core/Exception.hs index 59d6fe7..9744a38 100644 --- a/Haxl/Core/Exception.hs +++ b/Haxl/Core/Exception.hs @@ -5,6 +5,7 @@ -- found in the LICENSE file. An additional grant of patent rights can -- be found in the PATENTS file. +{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE DeriveDataTypeable #-} @@ -65,6 +66,7 @@ module Haxl.Core.Exception ( import Control.Exception import Data.Aeson +import Data.Binary (Binary) import Data.Typeable import Data.Text (Text) @@ -189,16 +191,16 @@ logicErrorFromException x = do -- | Generic \"critical\" exception. Something internal is -- borked. Panic. -data CriticalError = CriticalError Text - deriving (Typeable, Eq, Show) +newtype CriticalError = CriticalError Text + deriving (Typeable, Binary, Eq, Show) instance Exception CriticalError where toException = internalErrorToException fromException = internalErrorFromException -- | Generic \"something was not found\" exception. -data NotFound = NotFound Text - deriving (Typeable, Eq, Show) +newtype NotFound = NotFound Text + deriving (Typeable, Binary, Eq, Show) instance Exception NotFound where toException = logicErrorToException diff --git a/tests/TestTypes.hs b/tests/TestTypes.hs index 89781e2..d8e96d1 100644 --- a/tests/TestTypes.hs +++ b/tests/TestTypes.hs @@ -10,6 +10,7 @@ module TestTypes ) where import Data.Aeson +import Data.Binary (Binary) import Data.Text (Text) import qualified Data.Text as Text import qualified Data.HashMap.Strict as HashMap @@ -36,7 +37,7 @@ lookupInput field = do newtype Id = Id Int - deriving (Eq, Ord, Enum, Num, Integral, Real, Hashable, Typeable, + deriving (Eq, Ord, Binary, Enum, Num, Integral, Real, Hashable, Typeable, ToJSON, FromJSON) instance Show Id where