Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define JsonDecodeError and YamlDecodeError #12

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hw-prelude.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ library
HaskellWorks.Error
HaskellWorks.Error.Types
HaskellWorks.Error.Types.GenericError
HaskellWorks.Error.Types.JsonDecodeError
HaskellWorks.Error.Types.TimedOut
HaskellWorks.Error.Types.YamlDecodeError
HaskellWorks.FilePath
HaskellWorks.IO.Network.NamedPipe
HaskellWorks.IO.Network.Port
Expand Down
4 changes: 4 additions & 0 deletions src/HaskellWorks/Error/Types.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
module HaskellWorks.Error.Types (
GenericError (..),
JsonDecodeError (..),
TimedOut(..),
YamlDecodeError (..)
) where

import HaskellWorks.Error.Types.GenericError
import HaskellWorks.Error.Types.JsonDecodeError
import HaskellWorks.Error.Types.TimedOut
import HaskellWorks.Error.Types.YamlDecodeError
45 changes: 45 additions & 0 deletions src/HaskellWorks/Error/Types/JsonDecodeError.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NoFieldSelectors #-}
{-# LANGUAGE OverloadedRecordDot #-}

module HaskellWorks.Error.Types.JsonDecodeError
( JsonDecodeError(..)
, newJsonDecodeError
) where


import Data.Aeson (ToJSON (..), Value, (.=))
import qualified Data.Aeson as J
import GHC.Generics

import HaskellWorks.Prelude
import HaskellWorks.ToText

data JsonDecodeError =
JsonDecodeError
{ message :: Text
, bytestring :: Maybe ByteString
, text :: Maybe Text
, json :: Maybe Value
}
deriving (Eq, Generic, Show)

newJsonDecodeError :: ToText a => a -> JsonDecodeError
newJsonDecodeError message =
JsonDecodeError
{ message = toText message
, bytestring = Nothing
, text = Nothing
, json = Nothing
}

instance ToJSON JsonDecodeError where
toJSON e =
J.object
[ "error" .= id @Text "JsonDecodeError"
, "message" .= e.message
, "text" .= e.text
, "json" .= e.json
]
25 changes: 25 additions & 0 deletions src/HaskellWorks/Error/Types/YamlDecodeError.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}

module HaskellWorks.Error.Types.YamlDecodeError
( YamlDecodeError(..)
) where


import Data.Aeson (ToJSON (..), (.=))
import qualified Data.Aeson as J
import GHC.Generics
import HaskellWorks.Prelude
newtype YamlDecodeError =
YamlDecodeError
{ message :: Text
}
deriving (Eq, Generic, Show)

instance ToJSON YamlDecodeError where
toJSON e =
J.object
[ "error" .= id @Text "YamlDecodeError"
, "message" .= e.message
]
Loading