Error.hs 973 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
{-|
Module      : Gargantext.Database.Tree.Error
Description :
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

-}

{-# LANGUAGE QuasiQuotes       #-}

module Gargantext.Database.Query.Tree.Error
  where

import Control.Lens (Prism', (#))
18 19
import Control.Monad.Except (MonadError(throwError))

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
import Gargantext.Prelude

------------------------------------------------------------------------
data TreeError = NoRoot
               | EmptyRoot
               | TooManyRoots

instance Show TreeError
  where
    show NoRoot       = "Root node not found"
    show EmptyRoot    = "Root node should not be empty"
    show TooManyRoots = "Too many root nodes"

class HasTreeError e where
  _TreeError :: Prism' e TreeError

treeError :: ( MonadError e m
37
             , HasTreeError e )
38 39 40 41
             => TreeError
             -> m a
treeError te = throwError $ _TreeError # te