~zinigor/cardano-node/trunk

« back to all changes in this revision

Viewing changes to cardano-node/src/Cardano/Node/Orphans.hs

  • Committer: Igor Zinovyev
  • Date: 2021-08-13 19:12:27 UTC
  • Revision ID: zinigor@gmail.com-20210813191227-stlnsj3mc5ypwn0c
Tags: upstream-1.27.0
ImportĀ upstreamĀ versionĀ 1.27.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
{-# LANGUAGE StandaloneDeriving #-}
 
3
 
 
4
{-# OPTIONS_GHC -Wno-orphans #-}
 
5
 
 
6
module Cardano.Node.Orphans () where
 
7
 
 
8
import           Cardano.Prelude
 
9
import           Prelude (fail)
 
10
 
 
11
import           Data.Aeson (FromJSON (..), Value (..))
 
12
import qualified Data.Text as Text
 
13
 
 
14
import           Cardano.BM.Data.Tracer (TracingVerbosity (..))
 
15
import qualified Cardano.Chain.Update as Update
 
16
 
 
17
instance FromJSON TracingVerbosity where
 
18
  parseJSON (String str) = case str of
 
19
    "MinimalVerbosity" -> pure MinimalVerbosity
 
20
    "MaximalVerbosity" -> pure MaximalVerbosity
 
21
    "NormalVerbosity" -> pure NormalVerbosity
 
22
    err -> fail $ "Parsing of TracingVerbosity failed, "
 
23
                <> Text.unpack err <> " is not a valid TracingVerbosity"
 
24
  parseJSON invalid  = fail $ "Parsing of TracingVerbosity failed due to type mismatch. "
 
25
                           <> "Encountered: " <> show invalid
 
26
 
 
27
deriving instance Show TracingVerbosity
 
28
 
 
29
instance FromJSON Update.ApplicationName where
 
30
  parseJSON (String x) = pure $ Update.ApplicationName x
 
31
  parseJSON invalid  =
 
32
    fail $ "Parsing of application name failed due to type mismatch. "
 
33
    <> "Encountered: " <> show invalid