Skip to content

fix(typescript): guard appendFile against null/undefined for optional multipart file uploads#16713

Open
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/1782398075-fix-optional-file-upload-undefined
Open

fix(typescript): guard appendFile against null/undefined for optional multipart file uploads#16713
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/1782398075-fix-optional-file-upload-undefined

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes a regression in TypeScript SDK generation (v3.68.0+) where passing undefined to an optional multipart file upload field crashes with TypeError: Cannot use 'in' operator to search for 'path' in undefined.

The call chain appendFile("file", undefined)toMultipartDataPart(undefined)getFileWithMetadata(undefined)if ("path" in file) blows up because undefined is not an object.

Changes Made

  • FormDataWrapper.template.ts: Added if (value == null) { return; } at the top of all 4 appendFile implementations (Node18, Node16, Web, simple). Optional file fields silently skip when null/undefined, restoring pre-3.68.0 tolerance.
  • file.tsgetFileWithMetadata(): Added a null guard that throws a clear Error("Cannot upload null or undefined as a file. Ensure the file parameter is provided.") as defense-in-depth if toMultipartDataPart is called directly.
  • Unit tests added for both guards (file.test.ts + formDataWrapper.test.template.ts)
  • Seed outputs regenerated across all file-upload fixtures

Testing

  • Unit tests added/updated
    • file.test.ts: 4 tests covering toBinaryUploadRequest and toMultipartDataPart with null/undefined
    • formDataWrapper.test.template.ts: tests for appendFile silently skipping null/undefined in Node18, Web, and default implementations
  • Seed tests: all 8 file-upload fixtures pass
  • Local vitest: 415 tests pass in no-custom-config
  • CI: 50/50 checks passing

Link to Devin session: https://app.devin.ai/sessions/4b885de21ac744dbb59164c3ba84d68a


Open in Devin Review

… multipart file uploads

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

SDK Generation Benchmark Results

Comparing PR branch against median of 5 nightly run(s) on main (latest: 2026-06-25T05:19:47Z).

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
ts-sdk square 236s (n=5) 239s (n=5) 231s -5s (-2.1%)

main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).
Baseline from nightly runs on main (latest: 2026-06-25T05:19:47Z). Trigger benchmark-baseline to refresh.
Last updated: 2026-06-25 21:19 UTC

Swimburger and others added 2 commits June 25, 2026 19:00
…leWithMetadata

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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