Skip to content

fix: buffer archiver stream into Blob for native fetch/FormData compatibility#237

Open
Rohitbhise0004 wants to merge 3 commits intometacall:masterfrom
Rohitbhise0004:fix/protocol-error-api-update
Open

fix: buffer archiver stream into Blob for native fetch/FormData compatibility#237
Rohitbhise0004 wants to merge 3 commits intometacall:masterfrom
Rohitbhise0004:fix/protocol-error-api-update

Conversation

@Rohitbhise0004
Copy link
Copy Markdown

@Rohitbhise0004 Rohitbhise0004 commented Apr 2, 2026

Problem

@metacall/protocol >= 0.1.27 switched from axios to native fetch + FormData. The upload() function now calls:

fd.append('raw', blob, 'blob');

This requires a Blob argument. Previously, zip() returned a Node.js Transform stream (Archiver), which native FormData.append() cannot handle -- it corrupts or truncates the multipart body.

The FaaS server's busboy then throws Unexpected end of form and returns HTTP 400, causing the CI integration tests to fail.

Fix

Changed zip() in src/utils.ts to collect all archiver output chunks into a Buffer and return it wrapped in a Blob:

  • Listen for data events on the archiver to collect chunks
    • Call archive.finalize() and wait for the end event
    • Return new Blob([Buffer.concat(chunks)], { type: 'application/zip' })
    • Removed now-unused Archiver type import
      This is fully compatible with how @metacall/protocol passes the value to FormData.append().

CI Error (before fix)

X AxiosError: Request failed with status code 400
Error: Unexpected end of form
    at Multipart._final (node_modules/busboy/lib/types/multipart.js:588:17)

Protocol v0.1.28 replaced the axios-based ProtocolError (which had
.response.status / .response.data) with a plain custom Error class
that exposes .status and .data directly:

  Before: err.response?.status, err.response?.data
  After:  err.status, err.data

Fixes 10 ESLint errors:
- src/cli/messages.ts: unsafe .response?.status and .response?.data access
- src/auth.ts: 5x unsafe .response?.data access in auth flows
…tibility

@metacall/protocol >= 0.1.27 switched from axios to native fetch + FormData.
The upload() function now calls fd.append('raw', blob, 'blob') which requires
a Blob argument. The previous zip() returned a Node.js Transform stream
(Archiver) that native FormData cannot handle, causing a malformed multipart
body. The FaaS server's busboy then threw 'Unexpected end of form' and
returned HTTP 400.

Fix: collect all archiver data chunks into a Buffer and return it wrapped
in a Blob so it is compatible with native FormData.
@Rohitbhise0004 Rohitbhise0004 changed the title fix: update ProtocolError API usage to match @metacall/protocol v0.1.28 fix: buffer archiver stream into Blob for native fetch/FormData compatibility Apr 4, 2026
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