Skip to content

Offer a way to augment call stacks

Sometimes, I may want to capture some information that can be reported when an error occurs. Suppose I have

f x y = g x (h y)

g :: HasCallStack => ...
g x y = ..... (error "whoopsy") ....

I may want f to record information about y that will be reported if g throws an exception. As far as I can tell, the only currently supported way to do this is horrible and limited:

f x y = unsafeDupablePerformIO $
  catch (evaluate (g x (h y))) $ \e -> ....

I'd much rather have a function like

addMessage :: HasCallStack
           => String
           -> (HasCallStack => a)
           -> a

This would stick a string into the current call stack "frame" and call the argument. I imagine this can be implemented directly with the underlying implicit parameter, likely with a slight change to the CallStack representation.

Trac metadata
Trac field Value
Version 8.4.1
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Core Libraries
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information