Skip to content

fix: actionable error message in ExposedConnectionProvider#32

Merged
endrju19 merged 1 commit intomainfrom
feat/exposed-connection-provider-error-message
Apr 29, 2026
Merged

fix: actionable error message in ExposedConnectionProvider#32
endrju19 merged 1 commit intomainfrom
feat/exposed-connection-provider-error-message

Conversation

@endrju19
Copy link
Copy Markdown
Collaborator

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

  • ./gradlew :okapi-exposed:test --tests "*ExposedConnectionProviderTest*" — both cases pass
  • ./gradlew build — full project build, all existing tests pass
  • ./gradlew ktlintFormat — no formatting issues

When ExposedConnectionProvider.withConnection is called outside an active
Exposed transaction, TransactionManager.current() throws a generic Exposed
"No transaction in context" IllegalStateException that doesn't tell the
caller they are using okapi outside the expected transaction { } scope.

Wrap the lookup with TransactionManager.currentOrNull() and throw an
IllegalStateException whose message names the okapi method and points at
the missing Exposed transaction { } block. Test JdbcConnectionProvider
already does this same fail-fast on its ThreadLocal scope; this brings
ExposedConnectionProvider to parity.

Coverage:
  * ExposedConnectionProviderTest — unit (FunSpec):
    - throws IllegalStateException with actionable message when called
      outside any transaction
    - supplies the active transaction's connection to the block when
      called inside transaction(db) { }

Follow-up to PR #26 review feedback (code-reviewer Suggestion #6).
@endrju19 endrju19 merged commit 1b91d03 into main Apr 29, 2026
8 checks passed
@endrju19 endrju19 deleted the feat/exposed-connection-provider-error-message branch April 29, 2026 13:01
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.

1 participant