Skip to content

Commit

Permalink
add HasCallStack to more IO functions
Browse files Browse the repository at this point in the history
without these the callstack will end at these functions and there'll be no info about the caller
  • Loading branch information
dten committed Dec 12, 2023
1 parent e19230a commit 4ae6657
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Test/WebDriver/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ deleteKey :: (HasCallStack, WebDriver wd) => WebStorageType -> Text -> wd ()
deleteKey s k = noReturn $ doStorageCommand methodPost s ("/key/" `T.append` urlEncode k) Null

-- |A wrapper around 'doSessCommand' to create web storage requests.
doStorageCommand :: (WebDriver wd, ToJSON a, FromJSON b) =>
doStorageCommand :: (HasCallStack, WebDriver wd, ToJSON a, FromJSON b) =>
Method -> WebStorageType -> Text -> a -> wd b
doStorageCommand m s path a = doSessCommand m (T.concat ["/", s', path]) a
where s' = case s of
Expand All @@ -745,7 +745,7 @@ doStorageCommand m s path a = doSessCommand m (T.concat ["/", s', path]) a
-- |Get information from the server as a JSON 'Object'. For more information
-- about this object see
-- <https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#status>
serverStatus :: (WebDriver wd) => wd Value -- todo: make this a record type
serverStatus :: (HasCallStack, WebDriver wd) => wd Value -- todo: make this a record type
serverStatus = doCommand methodGet "/status" Null

-- |A record that represents a single log entry.
Expand Down Expand Up @@ -793,5 +793,5 @@ instance FromJSON ApplicationCacheStatus where
5 -> return Obsolete
err -> fail $ "Invalid JSON for ApplicationCacheStatus: " ++ show err

getApplicationCacheStatus :: (WebDriver wd) => wd ApplicationCacheStatus
getApplicationCacheStatus :: (HasCallStack, WebDriver wd) => wd ApplicationCacheStatus
getApplicationCacheStatus = doSessCommand methodGet "/application_cache/status" Null
12 changes: 6 additions & 6 deletions src/Test/WebDriver/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ instance WebDriver WD where

-- |Executes a 'WD' computation within the 'IO' monad, using the given
-- 'WDSession' as state for WebDriver requests.
runWD :: (HasCallStack) => WDSession -> WD a -> IO a
runWD :: HasCallStack => WDSession -> WD a -> IO a
runWD sess (WD wd) = evalStateT wd sess

-- |Executes a 'WD' computation within the 'IO' monad, automatically creating a new session beforehand.
Expand All @@ -93,27 +93,27 @@ runWD sess (WD wd) = evalStateT wd sess
-- Example:
--
-- > runSessionThenClose action = runSession myConfig . finallyClose $ action
runSession :: (HasCallStack) => WebDriverConfig conf => conf -> WD a -> IO a
runSession :: HasCallStack => WebDriverConfig conf => conf -> WD a -> IO a
runSession conf wd = do
sess <- mkSession conf
caps <- mkCaps conf
runWD sess $ createSession caps >> wd

-- |A finalizer ensuring that the session is always closed at the end of
-- the given 'WD' action, regardless of any exceptions.
finallyClose:: (HasCallStack) => WebDriver wd => wd a -> wd a
finallyClose:: HasCallStack => WebDriver wd => wd a -> wd a
finallyClose wd = closeOnException wd <* closeSession

-- |Exception handler that closes the session when an
-- asynchronous exception is thrown, but otherwise leaves the session open
-- if the action was successful.
closeOnException :: (HasCallStack) => WebDriver wd => wd a -> wd a
closeOnException :: HasCallStack => WebDriver wd => wd a -> wd a
closeOnException wd = wd `onException` closeSession

-- |Gets the command history for the current session.
getSessionHistory :: (HasCallStack) => WDSessionState wd => wd [SessionHistory]
getSessionHistory :: HasCallStack => WDSessionState wd => wd [SessionHistory]
getSessionHistory = fmap wdSessHist getSession

-- |Prints a history of API requests to stdout after computing the given action.
dumpSessionHistory :: (HasCallStack) => WDSessionStateControl wd => wd a -> wd a
dumpSessionHistory :: HasCallStack => WDSessionStateControl wd => wd a -> wd a
dumpSessionHistory = (`finally` (getSession >>= liftBase . print . wdSessHist))

0 comments on commit 4ae6657

Please sign in to comment.