-
-
Notifications
You must be signed in to change notification settings - Fork 77
Closed
Description
getElementById is typed to return a Maybe, but actually never returns a Nothing in case of failure, but throws an exception. I'd suggest to either actually return a Maybe or remove it from the type to make it clear it throws an exception. Also, the exception is unhelpful for understanding why generating the page failed, making it extremely hard to track down the error.
For now, I wrote this wrapper:
getElementByIdSafe :: Window -> String -> UI Element
getElementByIdSafe window elementID =
(liftIO $ try (runUI window $ getElementById window elementID)) >>= \case
Left (e :: SomeException) -> do
traceS TLError $ printf "getElementById for '%s' failed: %s" elementID (show e)
liftIO . throwIO $ e
Right Nothing -> do
traceS TLError $ printf "getElementById for '%s' failed" elementID
liftIO . throwIO $ userError "getElementById failure"
Right (Just e) ->
return e
This gives at least the failure reason and the name of the missing element.