Skip to content

fix: handle non-standard HTTP status codes (> 511) in FromResponseParser generation - #41

Merged
sauraww merged 1 commit into
masterfrom
fix/custom-status-code-generation
Mar 24, 2026
Merged

sauraww merged 1 commit into
masterfrom
fix/custom-status-code-generation

Conversation

@sauraww

@sauraww sauraww commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Network.HTTP.Types only provides predefined status constants up to status511. When a Smithy model uses @httpError with a non-standard code like 512, the codegen generates:

expectedStatus = Network.HTTP.Types.status512

This causes a compilation error since status512 doesn't exist in the module.

Fix

Added a statusExpression() helper in FromResponseParserGenerator that:

  • Uses the predefined constant (e.g. status200, status500) for standard codes (<= 511)
  • Uses mkStatus to construct the value at runtime for non-standard codes (> 511)

For example, @httpError(512) now generates:

expectedStatus = (Network.HTTP.Types.mkStatus 512 "")

Context

This was discovered when adding a WebhookFailed error with @httpError(512) to the superposition project (PR juspay/superposition#899).

Summary by CodeRabbit

  • Bug Fixes
    • Improved HTTP status code handling in the client code generator to properly support non-standard HTTP status codes.

@coderabbitai

coderabbitai Bot commented Mar 23, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0343b1bb-2f75-46be-b543-c9f3c51dfe75

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The change enhances HTTP status code handling in the Haskell client code generator. A new statusExpression() helper function conditionally generates status code expressions based on their numeric value, using direct function references for standard codes (≤511) and a constructor for non-standard codes.

Changes

Cohort / File(s) Summary
HTTP Status Code Generation
client-codegen/src/main/kotlin/in/juspay/smithy/haskell/client/codegen/generators/FromResponseParserGenerator.kt
Added statusExpression() helper to generate appropriate Haskell status code expressions, distinguishing between standard codes using Network.HTTP.Types.status<code> and non-standard codes using Network.HTTP.Types.mkStatus.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A status code dance, both high and low,

Five-eleven marks where standard flows go,

Beyond that bound, we construct with care,

mkStatus builds what's rare,

Now parser knows which path to take! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: handling non-standard HTTP status codes (> 511) in FromResponseParser generation, which aligns with the primary fix in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/custom-status-code-generation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between c686408 and 39fbdb0.

📒 Files selected for processing (1)
  • client-codegen/src/main/kotlin/in/juspay/smithy/haskell/client/codegen/generators/FromResponseParserGenerator.kt

Comment on lines +31 to +35
return if (status <= 511) {
"#{httpTypes:N}.status$status"
} else {
"(#{httpTypes:N}.mkStatus $status \"\")"
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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.

Suggested change
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.

@sauraww
sauraww force-pushed the fix/custom-status-code-generation branch from 39fbdb0 to e39ca0f Compare March 23, 2026 18:22
private val fieldMap =
shape.members().toList().associate { it.memberName to it.fieldName }

private fun statusExpression(): String {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@sauraww
sauraww force-pushed the fix/custom-status-code-generation branch from e39ca0f to 806d457 Compare March 23, 2026 18:34
@sauraww
sauraww merged commit 58dae02 into master Mar 24, 2026
9 checks passed
@sauraww
sauraww deleted the fix/custom-status-code-generation branch March 24, 2026 08:04
@coderabbitai coderabbitai Bot mentioned this pull request Mar 26, 2026
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.

2 participants