Skip to content
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

runNagiosPlugin can miss some exceptions #14

Open
ip1981 opened this issue Apr 29, 2016 · 1 comment
Open

runNagiosPlugin can miss some exceptions #14

ip1981 opened this issue Apr 29, 2016 · 1 comment

Comments

@ip1981
Copy link

ip1981 commented Apr 29, 2016

This approach does not catch all exceptions, e. g. when a state include some pure code which can throw exceptions, e. i. the state is evaluated afterrunNagiosPlugin' runs:

-- | Execute a Nagios check. The program will terminate at the check's
--   completion. A default status will provided if none is given.
runNagiosPlugin :: NagiosPlugin a -> IO ()
runNagiosPlugin check = do
    (_, st) <- runNagiosPlugin' $ E.catch check panic
    finishWith st
  where
    panic :: E.SomeException -> NagiosPlugin a
    panic = liftIO . finishWith . panicState

I had to use something like this (plugin :: IO (NagiosPlugin ()))

(plugin `catch` critical >>= runNagiosPlugin) `catch` foo
-- ...
critical :: SomeException -> IO (NagiosPlugin ())
critical = return . addResult Critical . T.pack . displayException
-- ...
foo :: MyError -> IO ()
foo e = critical (toException e) >>= runNagiosPlugin

Note that foo cannot catch all exceptions. otherwise it would catch ExitCode as well.

It's a kind of feature, not a bug :-)

@olorin
Copy link
Owner

olorin commented May 2, 2016

Thanks for the report. Could probably work around this by strictly evaluating the result, will have a look later this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants