fix(api): guard listOrganizations against non-array SDK responses (CLI-1CQ)#854
Merged
fix(api): guard listOrganizations against non-array SDK responses (CLI-1CQ)#854
Conversation
…I-1CQ) The @sentry/api SDK returns an empty object {} (not []) when the response body is empty, has Content-Length: 0, or status 204; and returns a ReadableStream when Content-Type is missing. The unsafe `as unknown as SentryOrganization[]` cast in listOrganizationsInRegion masked the type mismatch, causing `TypeError: l.map is not a function` in the self-hosted fallback path of listOrganizationsUncached. Self-hosted instances behind reverse proxies (nginx, Cloudflare, WAFs) commonly trigger this by stripping bodies or wrapping responses. Add Array.isArray guard after unwrapResult with a descriptive ApiError that names the region URL and the likely cause.
Contributor
|
Contributor
Codecov Results 📊✅ 6010 passed | Total: 6010 | Pass Rate: 100% | Execution Time: 0ms All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 12892 uncovered lines. Generated by Codecov Action |
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.
Summary
Fixes CLI-1CQ:
TypeError: l.map is not a functioninlistOrganizationsUncachedon self-hosted Sentry instances.Root cause
The
@sentry/apiSDK returnsdata = {}(not[]) when:Content-Length: 0It also returns a
ReadableStreamwhenContent-Typeis missing.unwrapResultreturnsdataas-is, and theas unknown as SentryOrganization[]cast inlistOrganizationsInRegionsilently lies. The crash surfaces in the self-hosted fallback path oflistOrganizationsUncachedwhen.map()is called on the non-array result.Self-hosted instances behind reverse proxies (nginx, Cloudflare, WAFs) commonly trigger this by stripping bodies or wrapping responses.
Fix
Add an
Array.isArrayguard inlistOrganizationsInRegionafterunwrapResult. If the data is not an array, throw a descriptiveApiErrorthat names the region URL and points at the likely cause (incompatible self-hosted version or proxy interference). This protects both the self-hosted path and the multi-region fan-out path, since both go throughlistOrganizationsInRegion.Tests
Three new tests in
test/lib/api/organizations.test.ts:{}body throwsApiErrorwith the right message + region URLApiError