Portability : POSIX
-}
-{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
-{-# OPTIONS_GHC -fno-warn-orphans #-}
+module Gargantext.Database.Query.Table.Node.Error where
-{-# LANGUAGE Arrows #-}
-{-# LANGUAGE ConstraintKinds #-}
-{-# LANGUAGE FunctionalDependencies #-}
-{-# LANGUAGE TemplateHaskell #-}
-{-# LANGUAGE TypeFamilies #-}
+import Control.Lens (Prism', (#), (^?))
+import Control.Monad.Except (MonadError(..))
+import Data.Text (Text)
-module Gargantext.Database.Query.Table.Node.Error where
+import Prelude hiding (null, id, map, sum)
import Gargantext.Database.Admin.Types.Node (NodeId)
-import Control.Lens (Prism', (#), (^?))
-import Control.Monad.Error.Class (MonadError(..))
import Gargantext.Prelude hiding (sum, head)
-import Prelude hiding (null, id, map, sum)
------------------------------------------------------------------------
data NodeError = NoListFound
| ManyNodeUsers
| DoesNotExist NodeId
| NeedsConfiguration
+ | NodeError Text
instance Show NodeError
where
show NotImplYet = "Not implemented yet"
show ManyParents = "Too many parents"
show ManyNodeUsers = "Many userNode/user"
- show (DoesNotExist n) = "Node does not exist" <> show n
+ show (DoesNotExist n) = "Node does not exist (" <> show n <> ")"
show NeedsConfiguration = "Needs configuration"
+ show (NodeError e) = "NodeError: " <> cs e
class HasNodeError e where
_NodeError :: Prism' e NodeError
+errorWith :: ( MonadError e m
+ , HasNodeError e)
+ => Text -> m a
+errorWith x = nodeError (NodeError x)
+
nodeError :: ( MonadError e m
, HasNodeError e)
=> NodeError -> m a