Skip to content

fix: defensive null checks for generated projection paths#136

Open
icebear0828 wants to merge 1 commit intogoogle-labs-code:mainfrom
icebear0828:fix/defensive-projection-null-checks
Open

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

Conversation

@icebear0828
Copy link
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
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.

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

1 participant