Skip to content

Fix display of HasCallStack backtraces when a test throws an error#472

Merged
Bodigrim merged 1 commit into
masterfrom
restore-HasCallStack-backtraces
Mar 24, 2026
Merged

Fix display of HasCallStack backtraces when a test throws an error#472
Bodigrim merged 1 commit into
masterfrom
restore-HasCallStack-backtraces

Conversation

@Bodigrim
Copy link
Copy Markdown
Collaborator

Closes #469. There are two parts:

@Bodigrim
Copy link
Copy Markdown
Collaborator Author

How to test this patch? Create a test, which throws an error, and observe tasty output. Here is a sample:

With GHC < 9.10:

    Foo: FAIL
      Exception: foo
      CallStack (from HasCallStack):
        error, called at Dependencies.hs:27:10 in core-tests-0.1-inplace-tasty-core-tests:Dependencies
        myTest, called at Dependencies.hs:20:20 in core-tests-0.1-inplace-tasty-core-tests:Dependencies

With GHC 9.10 (lots of garbage, but at least the first stack trace is relevant):

    Foo: FAIL
      Exception: foo
      CallStack (from HasCallStack):
        error, called at Dependencies.hs:27:10 in core-tests-0.1-inplace-tasty-core-tests:Dependencies
        myTest, called at Dependencies.hs:20:20 in core-tests-0.1-inplace-tasty-core-tests:Dependencies
      HasCallStack backtrace:
        collectBacktraces, called at libraries/ghc-internal/src/GHC/Internal/Exception.hs:169:13 in ghc-internal:GHC.Internal.Exception
        toExceptionWithBacktrace, called at libraries/ghc-internal/src/GHC/Internal/IO.hs:260:11 in ghc-internal:GHC.Internal.IO
        throwIO, called at ./Control/Concurrent/Async.hs:122:7 in tasty-1.5.3-inplace:Control.Concurrent.Async

With GHC 9.12:

    Foo: FAIL
      Exception: foo

      HasCallStack backtrace:
        error, called at Dependencies.hs:27:10 in core-tests-0.1-inplace-tasty-core-tests:Dependencies
        myTest, called at Dependencies.hs:20:20 in core-tests-0.1-inplace-tasty-core-tests:Dependencies

With GHC 9.14:

    Foo: FAIL
      Exception: ghc-internal:GHC.Internal.Exception.ErrorCall:

      foo

      HasCallStack backtrace:
        error, called at Dependencies.hs:27:10 in core-tests-0.1-inplace-tasty-core-tests:Dependencies
        myTest, called at Dependencies.hs:20:20 in core-tests-0.1-inplace-tasty-core-tests:Dependencies

I was not aiming to match the whole message between GHCs, because it would require much more CPP. But at least all of versions point to myTest instead of omitting stack traces entirely or interrupting them inside of Control.Concurrent.Async.

Copy link
Copy Markdown
Collaborator

@andreasabel andreasabel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a golden value test for this fix?

Comment thread core/Control/Concurrent/Async.hs
@Bodigrim Bodigrim force-pushed the restore-HasCallStack-backtraces branch from fdd0bfc to df0bd92 Compare March 24, 2026 00:47
@Bodigrim
Copy link
Copy Markdown
Collaborator Author

Is it possible to add a golden value test for this fix?

It's hard to do so: we are testing Tasty's output, so a golden test would have to run another instance of Tasty to collect its output. Then, as demonstated above, the output somewhat varies from version to version of GHC and contains highly volatile data (like exact line and column numbers).

There are two parts:

* Catch and rethrow exceptions with context in our vendored-in fork of `async`.
  This is inspired by upstream PR simonmar/async#165.
* Bridge over multiple changes to `displayException` in `base`
  to ensure that at least some stack trace is shown.
@Bodigrim Bodigrim force-pushed the restore-HasCallStack-backtraces branch from df0bd92 to 5ff0612 Compare March 24, 2026 01:00
@Bodigrim Bodigrim merged commit f661ae1 into master Mar 24, 2026
16 checks passed
@Bodigrim Bodigrim deleted the restore-HasCallStack-backtraces branch March 24, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing callstacks with GHC > 9.10

2 participants