KTOR-9423 CannotTransformContentToTypeException leaks internal class#5492
KTOR-9423 CannotTransformContentToTypeException leaks internal class#5492zibet27 wants to merge 1 commit intorelease/3.xfrom
Conversation
…names in response body
📝 WalkthroughWalkthroughThe PR centralizes content transformation exception handling by removing default receive-side error handling from BaseApplicationEngine and consolidating exception mapping in DefaultEnginePipeline. Both Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
ktor-server/ktor-server-plugins/ktor-server-status-pages/common/test/io/ktor/server/plugins/statuspages/StatusPagesTest.kt (1)
631-647: Please cover the default no-leak path too.Because this handler replaces the body, the test doesn't verify the actual leak fix in the default engine response. A companion case that triggers
CannotTransformContentToTypeExceptionthrough the receive path withoutStatusPageswould lock in the production 415/no-message behavior as well.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ktor-server/ktor-server-plugins/ktor-server-status-pages/common/test/io/ktor/server/plugins/statuspages/StatusPagesTest.kt` around lines 631 - 647, Add a companion test that exercises the default (no-StatusPages) path for CannotTransformContentToTypeException to ensure the engine returns the production 415/no-message behavior; specifically, create a setup that does not install StatusPages, has a routing POST that triggers throw CannotTransformContentToTypeException(typeOf<String>()), issues client.post("/") and asserts response.status is HttpStatusCode.UnsupportedMediaType and response.bodyAsText() is empty (or no message) so the leak fix is verified in the default receive path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@ktor-server/ktor-server-plugins/ktor-server-status-pages/common/test/io/ktor/server/plugins/statuspages/StatusPagesTest.kt`:
- Line 630: Rename the test function testCannotTransformContentToTypeException
to a descriptive backtick-style Kotlin test name (e.g., `fun \`cannot transform
content to target type returns appropriate status\`()`) to follow the
repository's **/test/**/*.kt naming convention; update the function declaration
(testCannotTransformContentToTypeException) and any references to it so the test
framework runs the new backtick name without changing behavior.
---
Nitpick comments:
In
`@ktor-server/ktor-server-plugins/ktor-server-status-pages/common/test/io/ktor/server/plugins/statuspages/StatusPagesTest.kt`:
- Around line 631-647: Add a companion test that exercises the default
(no-StatusPages) path for CannotTransformContentToTypeException to ensure the
engine returns the production 415/no-message behavior; specifically, create a
setup that does not install StatusPages, has a routing POST that triggers throw
CannotTransformContentToTypeException(typeOf<String>()), issues client.post("/")
and asserts response.status is HttpStatusCode.UnsupportedMediaType and
response.bodyAsText() is empty (or no message) so the leak fix is verified in
the default receive path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ae4f0fc2-8550-4a20-bafa-7e36299097e3
📒 Files selected for processing (3)
ktor-server/ktor-server-core/common/src/io/ktor/server/engine/BaseApplicationEngine.ktktor-server/ktor-server-core/common/src/io/ktor/server/engine/DefaultEnginePipeline.ktktor-server/ktor-server-plugins/ktor-server-status-pages/common/test/io/ktor/server/plugins/statuspages/StatusPagesTest.kt
| } | ||
|
|
||
| @Test | ||
| fun testCannotTransformContentToTypeException() = testApplication { |
There was a problem hiding this comment.
Use a descriptive backtick test name.
This new case should follow the repository's **/test/**/*.kt naming convention.
✏️ Rename suggestion
- fun testCannotTransformContentToTypeException() = testApplication {
+ fun `handles CannotTransformContentToTypeException via StatusPages`() = testApplication {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| fun testCannotTransformContentToTypeException() = testApplication { | |
| fun `handles CannotTransformContentToTypeException via StatusPages`() = testApplication { |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@ktor-server/ktor-server-plugins/ktor-server-status-pages/common/test/io/ktor/server/plugins/statuspages/StatusPagesTest.kt`
at line 630, Rename the test function testCannotTransformContentToTypeException
to a descriptive backtick-style Kotlin test name (e.g., `fun \`cannot transform
content to target type returns appropriate status\`()`) to follow the
repository's **/test/**/*.kt naming convention; update the function declaration
(testCannotTransformContentToTypeException) and any references to it so the test
framework runs the new backtick name without changing behavior.
Subsystem
Server
Motivation
KTOR-9423 CannotTransformContentToTypeException leaks internal class names in the response body
Solution
CannotTransformContentToTypeExceptioncatching, allowingStatusPagesto process it