Repository navigation
Commit 1b91d03
authored
fix: actionable error message in ExposedConnectionProvider (#32)
## Summary
- `ExposedConnectionProvider.withConnection` previously delegated to
`TransactionManager.current()`, which throws a generic Exposed
`IllegalStateException("No transaction in context")` when called outside
a transaction. The message gives no hint about okapi.
- Wrap with `TransactionManager.currentOrNull()` and throw a clearer
`IllegalStateException` naming the okapi method and the missing
`transaction { }` block. Brings `ExposedConnectionProvider` to parity
with how `JdbcConnectionProvider` (test helper) reports its own
missing-scope precondition.
- Added two unit tests: one for the negative path (asserts the message
contains both okapi method name and the `Exposed transaction { } block`
hint), one for the positive path (asserts the active Exposed connection
is supplied to the block).
## Motivation
Follow-up to PR #26 review feedback (`code-reviewer` Suggestion #6 on
the second review round). Three-line code change but it materially
improves diagnostics for users who hit this misconfiguration in Ktor +
Exposed setups.
## Test plan
- [x] `./gradlew :okapi-exposed:test --tests
"*ExposedConnectionProviderTest*"` — both cases pass
- [x] `./gradlew build` — full project build, all existing tests pass
- [x] `./gradlew ktlintFormat` — no formatting issues1 parent b42d914 commit 1b91d03
2 files changed
Lines changed: 42 additions & 4 deletions
File tree
- okapi-exposed/src
- main/kotlin/com/softwaremill/okapi/exposed
- test/kotlin/com/softwaremill/okapi/exposed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
0 commit comments