-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve feedback when plugin code throws exception #96
Comments
@isovector wrote in #95 :
Is this actually true? I've written and incredibly useful plugin below and I receive log messages and I see error messages in neovim. When calling the command
When calling the function with
When an autocmd is executed:
{-# LANGUAGE OverloadedStrings #-}
module Neovim.Example.Plugin.Throws where
import Neovim
import UnliftIO (throwIO)
throwExceptionFunction :: Neovim env ()
throwExceptionFunction = throwIO $ ErrorResult
"throwExceptionFunction"
(toObject (1 :: Int32, "Simulate neovim exception" :: String))
throwExceptionCommand :: CommandArguments -> Neovim env ()
throwExceptionCommand _ = throwExceptionFunction
throwExceptionAutoCommand :: Neovim env ()
throwExceptionAutoCommand = throwExceptionFunction {-# LANGUAGE TemplateHaskell, OverloadedStrings #-}
module Neovim.Example.Plugin ( plugin ) where
import Neovim.Example.Plugin.Throws (throwExceptionAutoCommand, throwExceptionCommand, throwExceptionFunction)
plugin :: Neovim () NeovimPlugin
plugin = do
wrapPlugin Plugin
{ environment = ()
, exports =
[ $(command' 'throwExceptionCommand) [CmdBang]
, $(function' 'throwExceptionFunction) Async
, $(autocmd 'throwExceptionAutoCommand) "FileType" Async def{acmdPattern = "vim"}
]
}
|
I experienced this issue when calling vim from an I can put together an mvp later today |
The following code swallows exceptions and if the second to last line is not commented, and exception is visible. neovimAsync :: (MonadUnliftIO m) => m a -> m (Async a)
neovimAsync m =
withRunInIO $ \lower ->
liftIO $ async $ lower m
throwExceptionFunctionAsync :: Neovim env Bool
throwExceptionFunctionAsync = do
spawned <- neovimAsync $ throwExceptionFunction
-- liftIO $ waitAnyCancel [spawned]
pure True I barely ever program in Haskell, but to me it seems that this is kind of expected behavior from the async library? |
Yeah, might be. Perhaps it's worth adding an async helper to the library that deals with this --- rather than doing the whole |
Sure! |
Or maybe just use: https://hackage.haskell.org/package/unliftio-0.2.20.1/docs/UnliftIO-Async.html |
No description provided.
The text was updated successfully, but these errors were encountered: