graphql-engine/server/lib/hasura-error-message/src/Hasura/Base/ErrorMessage.hs
Samir Talwar 699ba62def server: Rename "error-message" to "hasura-error-message".
There is already a library in Hackage called "error-message".

This breaks the Nix build as we end up overriding that library, which causes a change to any of its dependents.

Outside Nix, Shadowing isn't strictly a problem, but it's prudent to avoid it in case we accidentally end up with the other library in edge cases.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9679
GitOrigin-RevId: e3f54fd4e5eafec9b0a00128767daad0c8aeab72
2023-06-27 16:51:06 +00:00

37 lines
1.2 KiB
Haskell

-- | Error messages
--
-- This module defines a type for user facing error messages.
--
-- To construct a value of this type, use `toErrorMessage` or the 'IsString'
-- interface, the type class 'Hasura.Base.ToErrorValue' defined in the
-- "Hasura.Base.ToErrorValue" module, or use the utility functions defined in
-- the "Hasura.Base.ErrorValue" module.
--
-- 'ErrorMessage's can also be composed using the 'Semigroup' interface.
module Hasura.Base.ErrorMessage
( ErrorMessage,
toErrorMessage,
fromErrorMessage,
)
where
import Data.Aeson
import Data.String (IsString (..))
import Data.Text (Text)
import Data.Text qualified as Text
-- | 'ErrorMessage' wraps a 'Text' value such that it's easy to build up,
-- but difficult to break apart or extract the underlying text value.
newtype ErrorMessage = ErrorMessage
{ -- | A temporary extractor which will go away once 'ErrorMessage' is pervasive.
fromErrorMessage :: Text
}
deriving newtype (Eq, Semigroup, Monoid, ToJSON)
-- | A smart constructor for 'ErrorMessage' so that it cannot be deconstructed.
toErrorMessage :: Text -> ErrorMessage
toErrorMessage = ErrorMessage
instance IsString ErrorMessage where
fromString = ErrorMessage . Text.pack