Repository navigation
fix: handle non-standard HTTP status codes (> 511) in FromResponseParser generation - #41
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe change enhances HTTP status code handling in the Haskell client code generator. A new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 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 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
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@client-codegen/src/main/kotlin/in/juspay/smithy/haskell/client/codegen/generators/FromResponseParserGenerator.kt`:
- Around line 31-35: The conditional using "status <= 511" in
FromResponseParserGenerator (the return expression that currently picks
"#{httpTypes:N}.status$status" vs "(#{httpTypes:N}.mkStatus $status \"\")") is
unsafe because many numeric constants do not exist; change the logic so it
always uses mkStatus (i.e., emit "(#{httpTypes:N}.mkStatus $status \"\")"
unconditionally) instead of attempting to reference
"#{httpTypes:N}.status$status", keeping the same "status" variable and the
httpTypes import names.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c0226a4a-2a5b-4098-b548-b10c90757676
📒 Files selected for processing (1)
client-codegen/src/main/kotlin/in/juspay/smithy/haskell/client/codegen/generators/FromResponseParserGenerator.kt
| return if (status <= 511) { | ||
| "#{httpTypes:N}.status$status" | ||
| } else { | ||
| "(#{httpTypes:N}.mkStatus $status \"\")" | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Verify which status constants are actually exported by http-types.
# Expected: selected constants exist (e.g., status511), while many valid numeric
# codes do not (e.g., status299/status430/status510), proving the threshold check is insufficient.
curl -sSL "https://hackage.haskell.org/package/http-types-0.12.4/docs/src/Network.HTTP.Types.html" \
| rg -n 'status299|status430|status506|status510|status511'Repository: juspay/smithy-hs
Length of output: 280
status <= 511 is unsafe and will fail for non-standard codes in that range.
The condition at line 31 assumes every code up to 511 has a Network.HTTP.Types.status<code> constant. However, http-types exports only selected constants—for example, status299, status430, status506, and status510 do not exist, despite being ≤ 511. This will cause compilation failures when encountering these custom codes. Use mkStatus for all codes instead of relying on the numeric threshold.
Proposed fix
private fun statusExpression(): String {
- return if (status <= 511) {
- "#{httpTypes:N}.status$status"
- } else {
- "(#{httpTypes:N}.mkStatus $status \"\")"
- }
+ return "(#{httpTypes:N}.mkStatus $status \"\")"
}📝 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.
| return if (status <= 511) { | |
| "#{httpTypes:N}.status$status" | |
| } else { | |
| "(#{httpTypes:N}.mkStatus $status \"\")" | |
| } | |
| return "(#{httpTypes:N}.mkStatus $status \"\")" |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@client-codegen/src/main/kotlin/in/juspay/smithy/haskell/client/codegen/generators/FromResponseParserGenerator.kt`
around lines 31 - 35, The conditional using "status <= 511" in
FromResponseParserGenerator (the return expression that currently picks
"#{httpTypes:N}.status$status" vs "(#{httpTypes:N}.mkStatus $status \"\")") is
unsafe because many numeric constants do not exist; change the logic so it
always uses mkStatus (i.e., emit "(#{httpTypes:N}.mkStatus $status \"\")"
unconditionally) instead of attempting to reference
"#{httpTypes:N}.status$status", keeping the same "status" variable and the
httpTypes import names.
39fbdb0 to
e39ca0f
Compare
| private val fieldMap = | ||
| shape.members().toList().associate { it.memberName to it.fieldName } | ||
|
|
||
| private fun statusExpression(): String { |
There was a problem hiding this comment.
We don't need a function for this, right ?
We can just inline it in the place where it is needed right ?
…ser generation Network.HTTP.Types only provides predefined status constants up to status511. For non-standard codes like 512, the codegen now uses mkStatus to construct the value at runtime instead of referencing a non-existent constant. This fixes compilation errors when using @HttpError with codes > 511 in Smithy models.
e39ca0f to
806d457
Compare
Problem
Network.HTTP.Typesonly provides predefined status constants up tostatus511. When a Smithy model uses@httpErrorwith a non-standard code like512, the codegen generates:This causes a compilation error since
status512doesn't exist in the module.Fix
Added a
statusExpression()helper inFromResponseParserGeneratorthat:status200,status500) for standard codes (<= 511)mkStatusto construct the value at runtime for non-standard codes (> 511)For example,
@httpError(512)now generates:Context
This was discovered when adding a
WebhookFailederror with@httpError(512)to the superposition project (PR juspay/superposition#899).Summary by CodeRabbit