Skip to content

fix(api): guard listOrganizations against non-array SDK responses (CLI-1CQ)#854

Merged
BYK merged 1 commit intomainfrom
byk/fix-cli-1cq-list-orgs-non-array
Apr 27, 2026
Merged

fix(api): guard listOrganizations against non-array SDK responses (CLI-1CQ)#854
BYK merged 1 commit intomainfrom
byk/fix-cli-1cq-list-orgs-non-array

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 27, 2026

Summary

Fixes CLI-1CQ: TypeError: l.map is not a function in listOrganizationsUncached on self-hosted Sentry instances.

Root cause

The @sentry/api SDK returns data = {} (not []) when:

  • Response body is empty
  • Content-Length: 0
  • Status 204

It also returns a ReadableStream when Content-Type is missing.

unwrapResult returns data as-is, and the as unknown as SentryOrganization[] cast in listOrganizationsInRegion silently lies. The crash surfaces in the self-hosted fallback path of listOrganizationsUncached when .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.isArray guard in listOrganizationsInRegion after unwrapResult. If the data is not an array, throw a descriptive ApiError that 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 through listOrganizationsInRegion.

Tests

Three new tests in test/lib/api/organizations.test.ts:

  • valid array response works as before
  • empty object {} body throws ApiError with the right message + region URL
  • empty body throws ApiError

…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.
@github-actions
Copy link
Copy Markdown
Contributor

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-854/

Built to branch gh-pages at 2026-04-27 18:12 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
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

@BYK BYK merged commit 16e853b into main Apr 27, 2026
24 of 25 checks passed
@BYK BYK deleted the byk/fix-cli-1cq-list-orgs-non-array branch April 27, 2026 18:33
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.

1 participant