{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Cardano.Chain.Update.SystemTag (
  SystemTag (..),
  SystemTagError (..),
  checkSystemTag,
  systemTagMaxLength,
) where

import Cardano.Ledger.Binary (
  DecCBOR (..),
  Decoder,
  DecoderError (..),
  EncCBOR (..),
  FromCBOR (..),
  ToCBOR (..),
  cborError,
  decodeListLen,
  decodeWord8,
  encodeListLen,
  fromByronCBOR,
  matchSize,
  toByronCBOR,
 )
import Cardano.Prelude hiding (cborError)
import Data.Aeson (ToJSON, ToJSONKey)
import Data.Data (Data)
import qualified Data.Text as T
import Formatting (bprint, int, stext)
import qualified Formatting.Buildable as B
import NoThunks.Class (NoThunks (..))

-- | Tag of system for which update data is purposed, e.g. win64, mac32
newtype SystemTag = SystemTag
  { SystemTag -> Text
getSystemTag :: Text
  }
  deriving (SystemTag -> SystemTag -> Bool
(SystemTag -> SystemTag -> Bool)
-> (SystemTag -> SystemTag -> Bool) -> Eq SystemTag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SystemTag -> SystemTag -> Bool
== :: SystemTag -> SystemTag -> Bool
$c/= :: SystemTag -> SystemTag -> Bool
/= :: SystemTag -> SystemTag -> Bool
Eq, Eq SystemTag
Eq SystemTag =>
(SystemTag -> SystemTag -> Ordering)
-> (SystemTag -> SystemTag -> Bool)
-> (SystemTag -> SystemTag -> Bool)
-> (SystemTag -> SystemTag -> Bool)
-> (SystemTag -> SystemTag -> Bool)
-> (SystemTag -> SystemTag -> SystemTag)
-> (SystemTag -> SystemTag -> SystemTag)
-> Ord SystemTag
SystemTag -> SystemTag -> Bool
SystemTag -> SystemTag -> Ordering
SystemTag -> SystemTag -> SystemTag
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SystemTag -> SystemTag -> Ordering
compare :: SystemTag -> SystemTag -> Ordering
$c< :: SystemTag -> SystemTag -> Bool
< :: SystemTag -> SystemTag -> Bool
$c<= :: SystemTag -> SystemTag -> Bool
<= :: SystemTag -> SystemTag -> Bool
$c> :: SystemTag -> SystemTag -> Bool
> :: SystemTag -> SystemTag -> Bool
$c>= :: SystemTag -> SystemTag -> Bool
>= :: SystemTag -> SystemTag -> Bool
$cmax :: SystemTag -> SystemTag -> SystemTag
max :: SystemTag -> SystemTag -> SystemTag
$cmin :: SystemTag -> SystemTag -> SystemTag
min :: SystemTag -> SystemTag -> SystemTag
Ord, Int -> SystemTag -> ShowS
[SystemTag] -> ShowS
SystemTag -> String
(Int -> SystemTag -> ShowS)
-> (SystemTag -> String)
-> ([SystemTag] -> ShowS)
-> Show SystemTag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SystemTag -> ShowS
showsPrec :: Int -> SystemTag -> ShowS
$cshow :: SystemTag -> String
show :: SystemTag -> String
$cshowList :: [SystemTag] -> ShowS
showList :: [SystemTag] -> ShowS
Show, (forall x. SystemTag -> Rep SystemTag x)
-> (forall x. Rep SystemTag x -> SystemTag) -> Generic SystemTag
forall x. Rep SystemTag x -> SystemTag
forall x. SystemTag -> Rep SystemTag x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SystemTag -> Rep SystemTag x
from :: forall x. SystemTag -> Rep SystemTag x
$cto :: forall x. Rep SystemTag x -> SystemTag
to :: forall x. Rep SystemTag x -> SystemTag
Generic)
  deriving newtype (SystemTag -> Builder
(SystemTag -> Builder) -> Buildable SystemTag
forall p. (p -> Builder) -> Buildable p
$cbuild :: SystemTag -> Builder
build :: SystemTag -> Builder
B.Buildable)
  deriving anyclass (SystemTag -> ()
(SystemTag -> ()) -> NFData SystemTag
forall a. (a -> ()) -> NFData a
$crnf :: SystemTag -> ()
rnf :: SystemTag -> ()
NFData, Context -> SystemTag -> IO (Maybe ThunkInfo)
Proxy SystemTag -> String
(Context -> SystemTag -> IO (Maybe ThunkInfo))
-> (Context -> SystemTag -> IO (Maybe ThunkInfo))
-> (Proxy SystemTag -> String)
-> NoThunks SystemTag
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
$cnoThunks :: Context -> SystemTag -> IO (Maybe ThunkInfo)
noThunks :: Context -> SystemTag -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> SystemTag -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> SystemTag -> IO (Maybe ThunkInfo)
$cshowTypeOf :: Proxy SystemTag -> String
showTypeOf :: Proxy SystemTag -> String
NoThunks)

-- Used for debugging purposes only
instance ToJSON SystemTag

-- Used for debugging purposes only
instance ToJSONKey SystemTag

instance ToCBOR SystemTag where
  toCBOR :: SystemTag -> Encoding
toCBOR = SystemTag -> Encoding
forall a. EncCBOR a => a -> Encoding
toByronCBOR

instance FromCBOR SystemTag where
  fromCBOR :: forall s. Decoder s SystemTag
fromCBOR = Decoder s SystemTag
forall a s. DecCBOR a => Decoder s a
fromByronCBOR

instance EncCBOR SystemTag where
  encCBOR :: SystemTag -> Encoding
encCBOR = Text -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (Text -> Encoding) -> (SystemTag -> Text) -> SystemTag -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. SystemTag -> Text
getSystemTag

instance DecCBOR SystemTag where
  decCBOR :: forall s. Decoder s SystemTag
decCBOR = Text -> SystemTag
SystemTag (Text -> SystemTag) -> Decoder s Text -> Decoder s SystemTag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Text
forall s. Decoder s Text
forall a s. DecCBOR a => Decoder s a
decCBOR

systemTagMaxLength :: Integral i => i
systemTagMaxLength :: forall i. Integral i => i
systemTagMaxLength = i
10

data SystemTagError
  = SystemTagNotAscii Text
  | SystemTagTooLong Text
  deriving (SystemTagError -> SystemTagError -> Bool
(SystemTagError -> SystemTagError -> Bool)
-> (SystemTagError -> SystemTagError -> Bool) -> Eq SystemTagError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SystemTagError -> SystemTagError -> Bool
== :: SystemTagError -> SystemTagError -> Bool
$c/= :: SystemTagError -> SystemTagError -> Bool
/= :: SystemTagError -> SystemTagError -> Bool
Eq, Int -> SystemTagError -> ShowS
[SystemTagError] -> ShowS
SystemTagError -> String
(Int -> SystemTagError -> ShowS)
-> (SystemTagError -> String)
-> ([SystemTagError] -> ShowS)
-> Show SystemTagError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SystemTagError -> ShowS
showsPrec :: Int -> SystemTagError -> ShowS
$cshow :: SystemTagError -> String
show :: SystemTagError -> String
$cshowList :: [SystemTagError] -> ShowS
showList :: [SystemTagError] -> ShowS
Show, Typeable SystemTagError
Typeable SystemTagError =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> SystemTagError -> c SystemTagError)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c SystemTagError)
-> (SystemTagError -> Constr)
-> (SystemTagError -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c SystemTagError))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c SystemTagError))
-> ((forall b. Data b => b -> b)
    -> SystemTagError -> SystemTagError)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> SystemTagError -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> SystemTagError -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> SystemTagError -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> SystemTagError -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> SystemTagError -> m SystemTagError)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> SystemTagError -> m SystemTagError)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> SystemTagError -> m SystemTagError)
-> Data SystemTagError
SystemTagError -> Constr
SystemTagError -> DataType
(forall b. Data b => b -> b) -> SystemTagError -> SystemTagError
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> SystemTagError -> u
forall u. (forall d. Data d => d -> u) -> SystemTagError -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SystemTagError -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SystemTagError -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> SystemTagError -> m SystemTagError
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> SystemTagError -> m SystemTagError
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SystemTagError
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SystemTagError -> c SystemTagError
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SystemTagError)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SystemTagError)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SystemTagError -> c SystemTagError
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> SystemTagError -> c SystemTagError
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SystemTagError
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c SystemTagError
$ctoConstr :: SystemTagError -> Constr
toConstr :: SystemTagError -> Constr
$cdataTypeOf :: SystemTagError -> DataType
dataTypeOf :: SystemTagError -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SystemTagError)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c SystemTagError)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SystemTagError)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c SystemTagError)
$cgmapT :: (forall b. Data b => b -> b) -> SystemTagError -> SystemTagError
gmapT :: (forall b. Data b => b -> b) -> SystemTagError -> SystemTagError
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SystemTagError -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> SystemTagError -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SystemTagError -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> SystemTagError -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> SystemTagError -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> SystemTagError -> [u]
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> SystemTagError -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> SystemTagError -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> SystemTagError -> m SystemTagError
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> SystemTagError -> m SystemTagError
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> SystemTagError -> m SystemTagError
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> SystemTagError -> m SystemTagError
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> SystemTagError -> m SystemTagError
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> SystemTagError -> m SystemTagError
Data)

instance ToCBOR SystemTagError where
  toCBOR :: SystemTagError -> Encoding
toCBOR = SystemTagError -> Encoding
forall a. EncCBOR a => a -> Encoding
toByronCBOR

instance FromCBOR SystemTagError where
  fromCBOR :: forall s. Decoder s SystemTagError
fromCBOR = Decoder s SystemTagError
forall a s. DecCBOR a => Decoder s a
fromByronCBOR

instance EncCBOR SystemTagError where
  encCBOR :: SystemTagError -> Encoding
encCBOR SystemTagError
err = case SystemTagError
err of
    SystemTagNotAscii Text
tag ->
      Word -> Encoding
encodeListLen Word
2
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word8 -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (Word8
0 :: Word8)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Text -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR Text
tag
    SystemTagTooLong Text
tag ->
      Word -> Encoding
encodeListLen Word
2
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word8 -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR (Word8
1 :: Word8)
        Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Text -> Encoding
forall a. EncCBOR a => a -> Encoding
encCBOR Text
tag

instance DecCBOR SystemTagError where
  decCBOR :: forall s. Decoder s SystemTagError
decCBOR = do
    Int
len <- Decoder s Int
forall s. Decoder s Int
decodeListLen
    let checkSize :: Int -> Decoder s ()
        checkSize :: forall s. Int -> Decoder s ()
checkSize Int
size = Text -> Int -> Int -> Decoder s ()
forall s. Text -> Int -> Int -> Decoder s ()
matchSize Text
"SystemTagError" Int
size Int
len
    Word8
tag <- Decoder s Word8
forall s. Decoder s Word8
decodeWord8
    case Word8
tag of
      Word8
0 -> Int -> Decoder s ()
forall s. Int -> Decoder s ()
checkSize Int
2 Decoder s ()
-> Decoder s SystemTagError -> Decoder s SystemTagError
forall a b. Decoder s a -> Decoder s b -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Text -> SystemTagError
SystemTagNotAscii (Text -> SystemTagError)
-> Decoder s Text -> Decoder s SystemTagError
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Text
forall s. Decoder s Text
forall a s. DecCBOR a => Decoder s a
decCBOR
      Word8
1 -> Int -> Decoder s ()
forall s. Int -> Decoder s ()
checkSize Int
2 Decoder s ()
-> Decoder s SystemTagError -> Decoder s SystemTagError
forall a b. Decoder s a -> Decoder s b -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Text -> SystemTagError
SystemTagTooLong (Text -> SystemTagError)
-> Decoder s Text -> Decoder s SystemTagError
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Text
forall s. Decoder s Text
forall a s. DecCBOR a => Decoder s a
decCBOR
      Word8
_ -> DecoderError -> Decoder s SystemTagError
forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError (DecoderError -> Decoder s SystemTagError)
-> DecoderError -> Decoder s SystemTagError
forall a b. (a -> b) -> a -> b
$ Text -> Word8 -> DecoderError
DecoderErrorUnknownTag Text
"SystemTagError" Word8
tag

instance B.Buildable SystemTagError where
  build :: SystemTagError -> Builder
build = \case
    SystemTagNotAscii Text
tag ->
      Format Builder (Text -> Builder) -> Text -> Builder
forall a. Format Builder a -> a
bprint (Format (Text -> Builder) (Text -> Builder)
"SystemTag, " Format (Text -> Builder) (Text -> Builder)
-> Format Builder (Text -> Builder)
-> Format Builder (Text -> Builder)
forall b c a. Format b c -> Format a b -> Format a c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format Builder (Text -> Builder)
forall r. Format r (Text -> r)
stext Format Builder (Text -> Builder)
-> Format Builder Builder -> Format Builder (Text -> Builder)
forall b c a. Format b c -> Format a b -> Format a c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format Builder Builder
", contains non-ascii characters") Text
tag
    SystemTagTooLong Text
tag ->
      Format Builder (Text -> Int -> Builder) -> Text -> Int -> Builder
forall a. Format Builder a -> a
bprint
        (Format (Text -> Int -> Builder) (Text -> Int -> Builder)
"SystemTag, " Format (Text -> Int -> Builder) (Text -> Int -> Builder)
-> Format Builder (Text -> Int -> Builder)
-> Format Builder (Text -> Int -> Builder)
forall b c a. Format b c -> Format a b -> Format a c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format (Int -> Builder) (Text -> Int -> Builder)
forall r. Format r (Text -> r)
stext Format (Int -> Builder) (Text -> Int -> Builder)
-> Format Builder (Int -> Builder)
-> Format Builder (Text -> Int -> Builder)
forall b c a. Format b c -> Format a b -> Format a c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format (Int -> Builder) (Int -> Builder)
", exceeds limit of " Format (Int -> Builder) (Int -> Builder)
-> Format Builder (Int -> Builder)
-> Format Builder (Int -> Builder)
forall b c a. Format b c -> Format a b -> Format a c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Format Builder (Int -> Builder)
forall a r. Integral a => Format r (a -> r)
int)
        Text
tag
        (Int
forall i. Integral i => i
systemTagMaxLength :: Int)

checkSystemTag :: MonadError SystemTagError m => SystemTag -> m ()
checkSystemTag :: forall (m :: * -> *).
MonadError SystemTagError m =>
SystemTag -> m ()
checkSystemTag (SystemTag Text
tag)
  | Text -> Int
T.length Text
tag Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
forall i. Integral i => i
systemTagMaxLength = SystemTagError -> m ()
forall a. SystemTagError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (SystemTagError -> m ()) -> SystemTagError -> m ()
forall a b. (a -> b) -> a -> b
$ Text -> SystemTagError
SystemTagTooLong Text
tag
  | (Char -> Bool) -> Text -> Bool
T.any (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Char -> Bool
isAscii) Text
tag = SystemTagError -> m ()
forall a. SystemTagError -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (SystemTagError -> m ()) -> SystemTagError -> m ()
forall a b. (a -> b) -> a -> b
$ Text -> SystemTagError
SystemTagNotAscii Text
tag
  | Bool
otherwise = () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()