bracketOnErrorME :: MonadError e m => m a -> (a -> m b) -> (a -> m c) -> m c
bracketOnErrorME before after thing = do
  a <- before
  let handler e = after a >> throwError e
  catchError (thing a) handler

-- | Catch any IOErrors and convert them to a different type
bracketOnErrorME :: MonadError e m => m a -> (a -> m b) -> (a -> m c) -> m c
bracketOnErrorME before after thing = do
  a <- before
  let handler e = after a >> throwError e
  catchError (thing a) handler

-- | Catch any IOErrors and convert them to a different type
bracketOnErrorME before after thing = do
  a <- before
  let handler e = after a >> throwError e
  catchError (thing a) handler

-- | Catch any IOErrors and convert them to a different type