mfmts-1.0.0.0: cid/MultiFormats/CID/Errors.hs
-- | Module : MultiFormats.CID.Errors
-- Description : Provides Errors for CIDs
-- Copyright : Zoey McBride (c) 2026
-- License : AGPL-3.0-or-later
-- Maintainer : zoeymcbride@mailbox.org
-- Stability : experimental
module MultiFormats.CID.Errors
( Error (..),
Okay,
DataError (..),
EncodingError (..),
HashError (..),
)
where
import MultiFormats.VarInt.Errors qualified as VarInt
-- | Functor for wrapping CID processing function's return values.
type Okay t = Either Error t
-- | Sums up everything that can go wrong in the CID modules.
data Error
= InvalidData DataError
| InvalidEncoding EncodingError
| InvalidVarInt VarInt.Error
| InvalidHash HashError
deriving (Eq, Show)
-- | Errors with the CID itself, general/user caused errors.
data DataError
= -- | When the total input is empty.
EmptyCID
| -- | When the Item's codec can't be resolved from the MultiCodec table.
UnknownCodec
| -- | When String data was processed, but has extra unaccounted bytes.
TrailingBytes
deriving (Eq, Show)
-- | Errors arrising from the decoding process.
data EncodingError
= -- | When the leading byte indicates CIDv0 but is malformed.
MalformedCIDv0
| -- | When the CIDv1 is detected, but has an invalid leading codec.
ExpectedCIDv1
| -- | When the String encoding has an unknown/unimplemented prefix char.
UnknownBasePrefix
| -- | When the given string has an invalid character.
ImproperDigit
deriving (Eq, Show)
-- | Errors with the CID's MultiHash.
data HashError
= -- | If the given hash codec isn't for a hash function.
ExpectedHashCodec
| -- | If the encoded hash length doesn't match the digest size.
IncorrectLength
deriving (Eq, Show)