From 8f62c1ad5045564d8fd5ddafea877efc2d7fc803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 17 Oct 2026 20:40:33 +0200 Subject: Replace user error with custom error data type --- src/Error.hs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/Error.hs (limited to 'src/Error.hs') diff --git a/src/Error.hs b/src/Error.hs new file mode 100644 index 0000000..5226912 --- /dev/null +++ b/src/Error.hs @@ -0,0 +1,26 @@ +module Error ( + TesterError(..), + throwOtherError +) where + +import Control.Exception +import Control.Monad.Except +import Control.Monad.IO.Class + +import Data.Text (Text) +import Data.Text qualified as T + + +data TesterError + = OtherTesterError Text + +instance Show TesterError where + show = displayException + +instance Exception TesterError where + displayException = \case + OtherTesterError err -> T.unpack err + + +throwOtherError :: (MonadIO m, MonadError IOException m) => Text -> m a +throwOtherError = liftIO . throwIO . OtherTesterError -- cgit v1.2.3