IntersectMBO / IntersectMBO/cardano-node

Fix liftToIntegration exception handling and rename

Open
#6,567 3 comments 0 reactions 1 assignee Claimed by @palas View on GitHub
Dominant language
Haskell
Stars
3.2k
Forks
754
Avg merge
4d 20h
Merged PRs (30d)
20

Description

## Problem

`liftToIntegration` in `cardano-testnet/src/Testnet/Start/Cardano.hs:104` has two issues:

### 1. Duplicate exception messages

The current exception handler chain:

```haskell
catch @_ @SomeException (runRIO rMap r) (withFrozenCallStack $ failException . toException . stringException . displayException)
```

serializes the exception to a string via `displayException`, then wraps it in a new `StringException` (which captures its own callstack), then passes that to `failException` (which calls `displayException` again). This produces output like:

```
━━━ Exception (StringException) ━━━
UnliftIO.Exception.throwString called with:

! AnnotatedException !
Underlying exception type: StringException

UnliftIO.Exception.throwString called with:

Called from: ...

CallStack (from HasCallStack): ...
Called from: ...
```

The error message and callstack appear twice, and the exception type banners are nested three levels deep.

**Fix:** replace the chain with just `failException`, which already accepts `SomeException`:

```haskell
catch @_ @SomeException (runRIO rMap r) (withFrozenCallStack failException)
```

### 2. Unclear name

`liftToIntegration` doesn't convey what is being lifted from/to. A name like `runRIOInIntegration` would be clearer — it runs a `RIO ResourceMap` action inside Hedgehog's `Integration` monad.

## Context

Originally flagged as tech debt from https://github.com/IntersectMBO/cardano-node/pull/6346 (unresolved comments by @carbolymer), revisited in https://github.com/IntersectMBO/cardano-node/pull/6559#discussion_r3200025726.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.