    {-# LANGUAGE DeriveDataTypeable #-}
    {- |
       Module      : Data.GraphViz.Exception
       Description : Graphviz-specific exceptions
       Copyright   : (c) Ivan Lazar Miljenovic
       License     : 3-Clause BSD-style
       Maintainer  : Ivan.Miljenovic@gmail.com
    -}
    module Data.GraphViz.Exception
           ( GraphvizException(..)
             -- * Re-exported for convenience.
           , mapException
           , throw
           , throwIO
           , handle
           , bracket
           ) where

    import Control.Exception
    import Data.Typeable

    -- -----------------------------------------------------------------------------

    -- | Exceptions that arise from using this library fall into four
    --   categories:
    --
    --   * Unable to parse provided Dot code.
    --
    --   * Dot code is not valid UTF-8.
    --
    --   * An error when trying to run an external program (e.g. @dot@).
    --
    --   * Treating a non-custom Attribute as a custom one.
    --
    data GraphvizException = NotDotCode String
                           | NotUTF8Dot String
                           | GVProgramExc String
                           | NotCustomAttr String
                           deriving (GraphvizException -> GraphvizException -> Bool
    (GraphvizException -> GraphvizException -> Bool)
    -> (GraphvizException -> GraphvizException -> Bool)
    -> Eq GraphvizException
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: GraphvizException -> GraphvizException -> Bool
    == :: GraphvizException -> GraphvizException -> Bool
    $c/= :: GraphvizException -> GraphvizException -> Bool
    /= :: GraphvizException -> GraphvizException -> Bool
    Eq, Eq GraphvizException
    Eq GraphvizException =>
    (GraphvizException -> GraphvizException -> Ordering)
    -> (GraphvizException -> GraphvizException -> Bool)
    -> (GraphvizException -> GraphvizException -> Bool)
    -> (GraphvizException -> GraphvizException -> Bool)
    -> (GraphvizException -> GraphvizException -> Bool)
    -> (GraphvizException -> GraphvizException -> GraphvizException)
    -> (GraphvizException -> GraphvizException -> GraphvizException)
    -> Ord GraphvizException
    GraphvizException -> GraphvizException -> Bool
    GraphvizException -> GraphvizException -> Ordering
    GraphvizException -> GraphvizException -> GraphvizException
    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 :: GraphvizException -> GraphvizException -> Ordering
    compare :: GraphvizException -> GraphvizException -> Ordering
    $c< :: GraphvizException -> GraphvizException -> Bool
    < :: GraphvizException -> GraphvizException -> Bool
    $c<= :: GraphvizException -> GraphvizException -> Bool
    <= :: GraphvizException -> GraphvizException -> Bool
    $c> :: GraphvizException -> GraphvizException -> Bool
    > :: GraphvizException -> GraphvizException -> Bool
    $c>= :: GraphvizException -> GraphvizException -> Bool
    >= :: GraphvizException -> GraphvizException -> Bool
    $cmax :: GraphvizException -> GraphvizException -> GraphvizException
    max :: GraphvizException -> GraphvizException -> GraphvizException
    $cmin :: GraphvizException -> GraphvizException -> GraphvizException
    min :: GraphvizException -> GraphvizException -> GraphvizException
    Ord, Typeable)

    instance Show GraphvizException where
      showsPrec :: Int -> GraphvizException -> ShowS
    showsPrec Int
    _ (NotDotCode String
    str)    = String -> ShowS
    showString (String -> ShowS) -> String -> ShowS
    forall a b. (a -> b) -> a -> b
    $ String
    "Error when parsing Dot code:\n" String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    str
      showsPrec Int
    _ (NotUTF8Dot String
    str)    = String -> ShowS
    showString (String -> ShowS) -> String -> ShowS
    forall a b. (a -> b) -> a -> b
    $ String
    "Invalid UTF-8 Dot code: " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    str
      showsPrec Int
    _ (GVProgramExc String
    str)  = String -> ShowS
    showString (String -> ShowS) -> String -> ShowS
    forall a b. (a -> b) -> a -> b
    $ String
    "Error running utility program: " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    str
      showsPrec Int
    _ (NotCustomAttr String
    str) = String -> ShowS
    showString (String -> ShowS) -> String -> ShowS
    forall a b. (a -> b) -> a -> b
    $ String
    "Not a custom Attribute: " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ String
    str

    instance Exception GraphvizException