Skip to content

fix: defensive null checks for generated projection paths#136

Merged
davideast merged 1 commit intogoogle-labs-code:mainfrom
icebear0828:fix/defensive-projection-null-checks
Mar 29, 2026
Merged

fix: defensive null checks for generated projection paths#136
davideast merged 1 commit intogoogle-labs-code:mainfrom
icebear0828:fix/defensive-projection-null-checks

Conversation

@icebear0828
Copy link
Copy Markdown
Contributor

Summary

  • project.generate() and screen.edit() crash with TypeError: Cannot read properties of undefined when the API returns an incomplete response (missing outputComponents or screens)
  • The screen IS created server-side but the SDK fails to parse the response
  • screen.variants() already handles this correctly with optional chaining — generate() and edit() did not

Changes

  • emitProjection() now uses optional chaining (?.) for simple projection chains
  • generateReturnExpression() adds a _projected guard with a descriptive StitchError for single-object returns with non-empty projection paths
  • Empty projections (direct raw return) skip the guard to avoid unnecessary code
  • Regenerated SDK classes with the new defensive patterns
  • Added 5 tests covering incomplete API responses for generate() and edit()

Test plan

  • npx vitest run test/unit/sdk.test.ts — 20 tests passed (5 new)
  • npx vitest run — 81 tests passed, 0 regressions
  • bun scripts/generate-sdk.ts — regeneration succeeds

Closes #135

…labs-code#135)

project.generate() and screen.edit() crash with TypeError when the API
returns an incomplete response (e.g. missing outputComponents or screens).
The screen IS created server-side but the SDK fails to parse the response.

Changes:
- emitProjection() now uses optional chaining (?.) for simple projection chains
- generateReturnExpression() adds a _projected guard with a descriptive
  StitchError for single-object returns with non-empty projection paths
- Regenerated SDK classes with the new defensive patterns
- Added 5 tests covering incomplete API responses for generate() and edit()

Closes google-labs-code#135
@davideast davideast added the fleet-merge-ready Ready for fleet sequential merge label Mar 29, 2026
@davideast davideast merged commit f1d11f9 into google-labs-code:main Mar 29, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fleet-merge-ready Ready for fleet sequential merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

project.generate() crashes on incomplete API response — missing defensive null checks

2 participants