kowainik / cake-slayer

🍰🔪 Architecture of Haskell backend applications
https://kowainik.github.io/projects/cake-slayer
Mozilla Public License 2.0
132 stars 6 forks source link

[RFC] How to format multiple stack traces? #23

Open chshersh opened 5 years ago

chshersh commented 5 years ago

Currently we store only the last position of source code in error:

data ErrorWithSource err = ErrorWithSource
    { errorWithSourceCallStack :: !SourcePosition
    , errorWithSourceType      :: !err
    } deriving stock (Show, Eq, Functor)

This approach has problems that if we have helpers to throw errors, we won't see useful errors messages, unless we wrap those helpers explicitly in withFrozenCallStack. It's quite easy to forget to wrap. Morever, last position might not always be helpful. So I propose to change the data type to the following:

data ErrorWithSource err = ErrorWithSource
    { errorWithSourceCallStack :: !CallStack
    , errorWithSourceType      :: !err
    } deriving stock (Show, Eq, Functor)

And change formatting function:

toSourcePosition :: CallStack -> [SourcePosition]

And ideally it would be nice to pretty-print this list... What are your ideas? Single source postion is formatted like this:

CakeSlayer.Error.foo#42

How would you format multiple errors?