{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Neovim.Exceptions
( NeovimException(..)
, exceptionToDoc
) where
import Control.Exception (Exception)
import Data.MessagePack (Object (..))
import Data.String (IsString (..))
import Data.Text.Prettyprint.Doc (Doc, (<+>), viaShow)
import Data.Text.Prettyprint.Doc.Render.Terminal (AnsiStyle)
import Data.Typeable (Typeable)
data NeovimException
= ErrorMessage (Doc AnsiStyle)
| ErrorResult Object
deriving (Typeable, Show)
instance Exception NeovimException
instance IsString NeovimException where
fromString = ErrorMessage . fromString
exceptionToDoc :: NeovimException -> Doc AnsiStyle
exceptionToDoc = \case
ErrorMessage e ->
"Error message:" <+> e
ErrorResult o ->
"Result representing an error:" <+> viaShow o