Skip to content

fix!: require the compiler plugin marker for interpolation safety and fail fast on unknown modes - #434

Merged
zantvoort merged 3 commits into
mainfrom
fix/interpolation-safety-check
Aug 10, 2026
Merged

fix!: require the compiler plugin marker for interpolation safety and fail fast on unknown modes#434
zantvoort merged 3 commits into
mainfrom
fix/interpolation-safety-check

Conversation

@zantvoort

@zantvoort zantvoort commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Closes the three gaps in the interpolation safety backstop (#392):

  1. One explicit t() no longer exempts the template. Counting interpolations against t() calls is not implementable at runtime: a raw $name is plain string concatenation by the time the lambda executes, so nothing observable distinguishes it from literal SQL text. The sound contract is that the compiler plugin marker is the only verification signal; templates built without it now always trigger the configured mode. The mixed template from the issue warns (or fails) instead of passing silently.
  2. The mode switch is exhaustive. Unknown values throw an IllegalStateException naming the valid values instead of silently disabling the check. Matching is trimmed and case-insensitive, like the record and schema validation modes. (Unknown-value handling for those two siblings is inconsistent in opposite directions; filed as Validation modes: unknown values silently skip schema validation and silently escalate record validation #433.)
  3. The disabled mode is none, matching the documentation; the stray off spelling is gone.

The default mode stays warn; flipping the default to fail was flagged in the issue as possibly too breaking for this milestone. Instead the production hardening docs now state plainly that production deployments using Kotlin templates should set fail, since warn reduces a missing compiler plugin to a log line.

Breaking behavior changes

  • Templates built without the compiler plugin now warn by default even when they contain explicit t() calls (previously silent). The warning is logged once per JVM: one occurrence identifies the problem and the remedy is global, so repeating it per template would only flood the logs of applications that wrap interpolations manually. Remedy: apply the compiler plugin, or set -Dstorm.validation.interpolation_mode=none when every interpolation is wrapped manually.
  • Unknown mode values now throw at template build time (previously any unrecognized value disabled the check).

Repository CRUD and the typed query DSL are unaffected: the check runs only when a TemplateBuilder lambda is built, and the mode property is only consulted for templates without the marker.

storm-kotlinx-serialization now compiles its tests with the compiler plugin; its integration tests build template lambdas with explicit t() and would otherwise warn under the new semantics.

Docs: docs/string-templates.md and docs/configuration.md updated (docs/ only, so the change shows at /docs/next and goes live with the next release snapshot).

Tested: new InterpolationSafetyTest (9 tests) uses named TemplateContext extension functions, which the plugin transformer leaves untouched, to model plugin-less templates inside a plugin-compiled module. Full storm-kotlin (1712) and storm-kotlinx-serialization (192) suites green.

Fixes #392

… fail fast on unknown modes

Explicit t() or interpolate() calls no longer satisfy the interpolation
safety check: a single call exempted the whole template, letting every
other raw interpolation pass silently. A raw interpolation is plain
string concatenation by the time the lambda runs, so the plugin marker
is the only signal that can verify a template; without it, the
configured mode now always applies.

The mode switch is exhaustive: warn, fail and none are matched after
trimming and case normalization, and any other value throws an
IllegalStateException naming the valid values instead of silently
disabling the check. The disabled mode is spelled none, matching the
documentation.

storm-kotlinx-serialization compiles its tests with the compiler plugin
so its template lambdas carry the marker.

Fixes #392
@zantvoort zantvoort added this to the 1.14.0 milestone Aug 10, 2026
@zantvoort
zantvoort merged commit 9aa7919 into main Aug 10, 2026
7 checks passed
@zantvoort
zantvoort deleted the fix/interpolation-safety-check branch August 10, 2026 10:08
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../src/main/kotlin/st/orm/template/TemplateString.kt 90.90% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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.

Interpolation safety check: bypassed by one explicit t(), no else on the mode switch, mode name mismatch

1 participant