fix: Raise a Seam error for a success response that is malformed - #574
Open
razor-x wants to merge 1 commit into
Open
fix: Raise a Seam error for a success response that is malformed#574razor-x wants to merge 1 commit into
razor-x wants to merge 1 commit into
Conversation
Every generated route read its resource straight out of res.body, so a 2xx response with an unexpected envelope, a proxy rewrite, a gateway page with a JSON content type, or a renamed response key surfaced as a bare NoMethodError on nil or String from deep inside the resource loader, or as a silent nil. A 3xx passed through untouched because Faraday's RaiseError only covers 400 through 599. The action attempt poll and the paginator's pagination envelope failed the same way, the latter by silently ending iteration. Add Seam::Http::InvalidResponseError and a Seam::Http::Response helper that reads the response key for an object, a list, or the pagination envelope, naming the endpoint, the expected key, and what arrived instead. Generate every route through it, and route the action attempt poll and the paginator through the same helper. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SQW83gyXeUG61RDrHEky97
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SDK audit finding M3. A 2xx with an unexpected envelope (proxy rewrite, gateway maintenance page with a JSON content type, response-key rename) escaped the SDK's error hierarchy: generated routes did
res.body["device"]and the resource loader raised a bareNoMethodErroron nil or String, or returned nil silently. A 3xx passed straight through, since Faraday'sRaiseErroronly covers 400–599, so a redirecting endpoint yielded nil instead of an error. The action-attempt poll crashed the same way mid-wait, and the paginator silently ended iteration when thepaginationobject was missing.Fix
Ported from seamapi/python#638 and seamapi/php#475, with the same message shape as the other three SDKs:
Seam::Http::InvalidResponseErrorwithpathandresponse_key.Seam::Http::Response.read/.read_list/.read_paginationinlib/seam/response.rb.client-method.hbsreads every route's response through the helper, choosingread_listfrom the blueprint'sresource_listresponse type. Regenerated diff is exactly the 96 resource unwraps, the 23 action-attempt unwraps, and onerequireper route file.ActionAttemptResolverand the paginator use the same helper. The paginator's middleware now hands the body and request path to the paginator, which validates the pagination envelope, so a list route that returns nopaginationraises instead of silently stopping.A 2xx whose body is declared JSON but does not parse still raises
Faraday::ParsingErrorfrom Faraday's JSON middleware, as before; that case is pinned in the spec.Tests
New
spec/seam_client/invalid_response_spec.rb(WebMock): missing key, wrong key, null body, string body, plain text, non-object under key, non-list under list key, 302, malformed poll response mid-wait, missing and non-object pagination throughcreate_paginator. Every message is pinned exactly.Revert-check against
main: 11 failures, with the audit's symptoms (undefined method 'each' for nil,undefined method '[]' for nil, and "nothing was raised" for the redirect and pagination cases).🤖 Generated with Claude Code
https://claude.ai/code/session_01SQW83gyXeUG61RDrHEky97
Generated by Claude Code