Skip to content

Commit

Permalink
print sql query if errors
Browse files Browse the repository at this point in the history
  • Loading branch information
CSchank committed Aug 12, 2021
1 parent 2daff06 commit 9d91885
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions IHP/ModelSupport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,16 @@ measureTimeIfLogging queryAction theQuery theParameters = do
if currentLogLevel == Debug
then do
start <- getCurrentTime
result <- queryAction
end <- getCurrentTime
let theTime = end `diffUTCTime` start
logQuery theQuery theParameters theTime
pure result
result <- try $ queryAction

case result of
Left (e :: SomeException) -> do
error $ replicate "=" 30 <> "\nError in query: \n" <> show theQuery <> "\n" <> show e <> replicate "=" 30
Right result -> do
end <- getCurrentTime
let theTime = end `diffUTCTime` start
logQuery theQuery theParameters theTime
pure result
else queryAction

-- | Runs a raw sql query
Expand Down

0 comments on commit 9d91885

Please sign in to comment.