From d4c2170b56b94497e37c94e5e3c9ee6f18a2ed43 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 14 Feb 2016 21:43:05 +0000 Subject: Some more useful constructors for PrintingError --- server/test/Thermoprint/Server/QueueSpec.hs | 2 +- spec/src/Thermoprint/API.hs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/server/test/Thermoprint/Server/QueueSpec.hs b/server/test/Thermoprint/Server/QueueSpec.hs index fd45e1b..c39083a 100644 --- a/server/test/Thermoprint/Server/QueueSpec.hs +++ b/server/test/Thermoprint/Server/QueueSpec.hs @@ -23,7 +23,7 @@ instance Arbitrary QueueEntry where arbitrary = QueueEntry <$> arbitrary <*> arbitrary instance Arbitrary PrintingError where - arbitrary = oneof [ return UnknownError + arbitrary = oneof [ return (IOError "dummy") ] instance Arbitrary JobId where diff --git a/spec/src/Thermoprint/API.hs b/spec/src/Thermoprint/API.hs index 6c020fc..6f7fc02 100644 --- a/spec/src/Thermoprint/API.hs +++ b/spec/src/Thermoprint/API.hs @@ -1,5 +1,6 @@ {-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} {-# LANGUAGE TypeOperators, DataKinds #-} +{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE OverloadedStrings #-} -- | A specification of an API for interacting with a set of printers @@ -59,8 +60,16 @@ data JobStatus = Queued PrinterId | Failed PrintingError deriving (Generic, Show, FromJSON, ToJSON) -data PrintingError = UnknownError - deriving (Typeable, Generic, NFData, Show, FromJSON, ToJSON, Exception) +deriving instance Generic EncodingException +deriving instance NFData EncodingException +deriving instance FromJSON EncodingException +deriving instance ToJSON EncodingException + +data PrintingError = IOError String -- ^ Not the actual error because we can't marshal that to JSON + | EncError EncodingException -- ^ Could not encode some part of the 'Printout' + deriving (Typeable, Generic, NFData, Show, FromJSON, ToJSON) + +instance Exception PrintingError type DraftTitle = Text -- cgit v1.2.3