File tree Expand file tree Collapse file tree 4 files changed +76
-0
lines changed
Expand file tree Collapse file tree 4 files changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,9 @@ library
9696 HaskellWorks.Error
9797 HaskellWorks.Error.Types
9898 HaskellWorks.Error.Types.GenericError
99+ HaskellWorks.Error.Types.JsonDecodeError
99100 HaskellWorks.Error.Types.TimedOut
101+ HaskellWorks.Error.Types.YamlDecodeError
100102 HaskellWorks.FilePath
101103 HaskellWorks.IO.Network.NamedPipe
102104 HaskellWorks.IO.Network.Port
Original file line number Diff line number Diff line change 11module HaskellWorks.Error.Types (
22 GenericError (.. ),
3+ JsonDecodeError (.. ),
34 TimedOut (.. ),
5+ YamlDecodeError (.. )
46) where
57
68import HaskellWorks.Error.Types.GenericError
9+ import HaskellWorks.Error.Types.JsonDecodeError
710import HaskellWorks.Error.Types.TimedOut
11+ import HaskellWorks.Error.Types.YamlDecodeError
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE DataKinds #-}
2+ {-# LANGUAGE DeriveGeneric #-}
3+ {-# LANGUAGE DuplicateRecordFields #-}
4+ {-# LANGUAGE NoFieldSelectors #-}
5+ {-# LANGUAGE OverloadedRecordDot #-}
6+
7+ module HaskellWorks.Error.Types.JsonDecodeError
8+ ( JsonDecodeError (.. )
9+ , newJsonDecodeError
10+ ) where
11+
12+
13+ import Data.Aeson (ToJSON (.. ), Value , (.=) )
14+ import qualified Data.Aeson as J
15+ import GHC.Generics
16+
17+ import HaskellWorks.Prelude
18+ import HaskellWorks.ToText
19+
20+ data JsonDecodeError =
21+ JsonDecodeError
22+ { message :: Text
23+ , bytestring :: Maybe ByteString
24+ , text :: Maybe Text
25+ , json :: Maybe Value
26+ }
27+ deriving (Eq , Generic , Show )
28+
29+ newJsonDecodeError :: ToText a => a -> JsonDecodeError
30+ newJsonDecodeError message =
31+ JsonDecodeError
32+ { message = toText message
33+ , bytestring = Nothing
34+ , text = Nothing
35+ , json = Nothing
36+ }
37+
38+ instance ToJSON JsonDecodeError where
39+ toJSON e =
40+ J. object
41+ [ " error" .= id @ Text " JsonDecodeError"
42+ , " message" .= e. message
43+ , " text" .= e. text
44+ , " json" .= e. json
45+ ]
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE DataKinds #-}
2+ {-# LANGUAGE DeriveGeneric #-}
3+ {-# LANGUAGE DuplicateRecordFields #-}
4+
5+ module HaskellWorks.Error.Types.YamlDecodeError
6+ ( YamlDecodeError (.. )
7+ ) where
8+
9+
10+ import Data.Aeson (ToJSON (.. ), (.=) )
11+ import qualified Data.Aeson as J
12+ import GHC.Generics
13+ import HaskellWorks.Prelude
14+ newtype YamlDecodeError =
15+ YamlDecodeError
16+ { message :: Text
17+ }
18+ deriving (Eq , Generic , Show )
19+
20+ instance ToJSON YamlDecodeError where
21+ toJSON e =
22+ J. object
23+ [ " error" .= id @ Text " YamlDecodeError"
24+ , " message" .= e. message
25+ ]
You can’t perform that action at this time.
0 commit comments