Skip to content

fix(fetch): preserve response size errors across runtime wrappers - #11179

Merged
jasonsaayman merged 6 commits into
axios:v1.xfrom
vjymisal0:fix/fetch-adapter-max-length-error-unmasking
Sep 16, 2026
Merged

jasonsaayman merged 6 commits into
axios:v1.xfrom
vjymisal0:fix/fetch-adapter-max-length-error-unmasking

Conversation

@vjymisal0

@vjymisal0 vjymisal0 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When a fetch response exceeds maxContentLength, some runtimes replace the stream error with a generic fetch failure. Preserve the current request's original ERR_BAD_RESPONSE, config, and request even when the runtime drops the cause.

  • Keep response-size errors local to each adapter invocation. Unrelated fetch failures retain network-error handling.
  • Preserve the existing env.Response constructor signatures and document their conditional runtime stream requirements in both public declarations. Custom implementations must accept tracked ReadableStream<Uint8Array> bodies for enabled maxContentLength limits, download progress, or cancellation/timeout tracking of stream/response results.
  • Cover legacy and stream-compatible wrappers, general ArrayBufferView inputs, invalid bodies, and Node-only imports in both ESM and CommonJS declaration tests.
  • Add Chromium, Firefox, and WebKit regressions for wrapped text, array-buffer, and blob reads, plus concurrent and subsequent requests using a cached adapter.
  • Make the affected DNS test deterministic and record prerelease documentation notes, including size-limit tracking without a progress callback.

Validation

Rebased onto v1.x at ed95c083, preserving its cache-mode fix and isolated fetch test servers.

  • npm run lint, npm run build, and npm pack --ignore-scripts passed.
  • Fetch adapter unit suite: 82 passed on Node 26.8.1.
  • Response-error and cache browser suites: 30 passed across Chromium, Firefox, and WebKit.
  • Freshly packed module suites: ESM 7 passed; CommonJS 8 passed, including TypeScript 5.9.3 and 4.9.5 declaration checks.
  • Freshly packed smoke suites: ESM 74 passed; CommonJS 70 passed.
  • Verified both public declarations have identical type tokens to the base; only documentation comments differ. Verified all four packed suites contain the current declarations and runtime artifacts.
  • Regression controls confirmed constructor compatibility tests fail against the earlier PR declarations and browser error tests fail against the base adapter.

Compatibility

Patch fix preserving existing size limits, default adapter selection, constructor signatures, and genuine network-error handling. No migration is required. The legacy constructor body type does not express conditional stream inputs; its documentation now states the existing runtime requirement explicitly without narrowing accepted constructors or introducing DOM-only type dependencies.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread lib/adapters/fetch.js Resolved
Comment thread index.d.cts Resolved
@greptile-apps

greptile-apps Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The fetch adapter correctly isolates foreign AxiosErrors carried as the cause of a fetch-shaped network failure. The exercised request returned a new ERR_NETWORK error for the current request rather than exposing the foreign request's error, configuration, or request object.

A custom env.Response constructor can still be accepted by the ESM and CommonJS declarations even though it cannot accept the ReadableStream that Axios supplies when download progress is enabled. The exercised request then fails while Axios reconstructs the response.

Confidence Score: 4/5

The fetch error-handling change behaves correctly, but the public Response override contract remains incompatible with streamed response tracking.

One actionable non-security request-failure issue remains: a declared custom Response constructor can reject the streamed body Axios passes during download-progress handling.

Files Needing Attention: index.d.ts, index.d.cts

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex executed a Node reproduction through the public Axios entry point with adapter: 'fetch' and a configured env.fetch, observing a fetch-shaped TypeError whose cause was a foreign AxiosError.
  • T-Rex ran the focused repository fetch-adapter regression test, which passed.
  • T-Rex produced proofs for two P1 findings and linked the corresponding reviewer comments.
  • Before and after capture validations confirmed the expected error flow, and the focused regression test passes.
  • End-to-end validation shows that reconstructing a ReadableStream with StringOnlyResponse leads to a TypeError surfaced by Axios as isAxiosError, with ESM and CJS declarations reproduced and exit code 0, identifying the compatibility gap source.

View all artifacts

T-Rex Ran code and verified through T-Rex

Comments Outside Diff (2)
  1. index.d.ts, line 455-458 (link)

    P1 Response constructor rejects streams

    The declared env.Response constructor accepts the legacy non-stream body union, but the fetch adapter passes trackStream(...) to this constructor whenever onDownloadProgress is enabled. An ESM and CJS declaration reproduction accepted the declared constructor shape, while the runtime reproduction showed the custom constructor throwing when Axios supplied the ReadableStream. Require a constructor body type that accepts the streamed body Axios supplies, and mirror that requirement in index.d.cts.

    Artifacts

    ESM declaration acceptance reproduction source

    • This authored ESM TypeScript consumer passes the legacy declaration-shaped Response constructor to Axios, showing the accepted contract.

    ESM narrow constructor rejection reproduction source

    • This authored ESM TypeScript consumer supplies a string-only Response constructor to establish the narrower unsafe constructor boundary.

    CJS declaration acceptance reproduction source

    • This authored CJS TypeScript consumer passes the legacy declaration-shaped Response constructor to Axios, showing the CJS contract matches the ESM gap.

    CJS narrow constructor rejection reproduction source

    • This authored CJS TypeScript consumer supplies a string-only Response constructor to establish the narrower unsafe constructor boundary.

    Fetch adapter streaming runtime reproduction source

    • This authored executable mock-fetch reproduction compares native and string-only Response constructors while requesting download progress, showing the reconstructed stream requirement.

    ESM declaration acceptance output

    • This captured TypeScript compilation of the ESM legacy declaration-shaped constructor exited 0, proving the current ESM declaration accepts it.

    ESM narrow constructor rejection output

    • This captured TypeScript compilation rejects the ESM string-only constructor because the declared legacy union requires additional non-stream body forms.

    CJS declaration acceptance output

    • This captured TypeScript compilation of the CJS legacy declaration-shaped constructor exited 0, proving the current CJS declaration accepts it.

    CJS narrow constructor rejection output

    • This captured TypeScript compilation rejects the CJS string-only constructor because the declared legacy union requires additional non-stream body forms.

    Native Response download-progress runtime output

    • This captured native Response run resolved with the downloaded payload and a download-progress event, proving the normal streamed path works.

    String-only Response download-progress runtime output

    • This captured string-only Response run rejected when Axios passed a ReadableStream during response reconstruction, proving the claimed runtime consequence.

    Focused fetch adapter unit-suite output

    • This captured focused Vitest run passed all 82 fetch-adapter tests, showing the existing suite does not cover the custom Response constructor incompatibility.

    View artifacts

    T-Rex Ran code and verified through T-Rex

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: index.d.ts
    Line: 455-458
    
    Comment:
    **Response constructor rejects streams**
    
    The declared `env.Response` constructor accepts the legacy non-stream body union, but the fetch adapter passes `trackStream(...)` to this constructor whenever `onDownloadProgress` is enabled. An ESM and CJS declaration reproduction accepted the declared constructor shape, while the runtime reproduction showed the custom constructor throwing when Axios supplied the `ReadableStream`. Require a constructor body type that accepts the streamed body Axios supplies, and mirror that requirement in `index.d.cts`.
    
    ---
    
    For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
  2. General comment

    P1 Custom env.Response type allows constructors that cannot support Axios streaming reconstruction

    • Bug
      • Both index.d.ts and index.d.cts declare env.Response with a legacy body union that excludes ReadableStream, yet lib/adapters/fetch.js replaces a streamed response with new Response(trackStream(...), options) whenever onDownloadProgress is enabled (also for stream-based max-content-length and selected response/cancellation paths). A consumer can therefore provide a constructor accepted by TypeScript which throws at runtime on Axios's ReadableStream body.
    • Cause
      • The declaration body union is intentionally retained as a legacy type despite being narrower than the adapter's actual required capability; JSDoc states the requirement but cannot enforce it.
    • Fix
      • Update both declaration entry points to require a Response-compatible constructor whose first parameter includes ReadableStream<Uint8Array> (preferably a body type aligned with the supported DOM BodyInit version), or introduce a separately named legacy opt-in that disables streaming-dependent adapter features. Add ESM/CJS type tests and a runtime test for a rejecting custom constructor.

    T-Rex Ran code and verified through T-Rex

Prompt To Fix All With AI
### Issue 1
index.d.ts:455-458
**Response constructor rejects streams**

The declared `env.Response` constructor accepts the legacy non-stream body union, but the fetch adapter passes `trackStream(...)` to this constructor whenever `onDownloadProgress` is enabled. An ESM and CJS declaration reproduction accepted the declared constructor shape, while the runtime reproduction showed the custom constructor throwing when Axios supplied the `ReadableStream`. Require a constructor body type that accepts the streamed body Axios supplies, and mirror that requirement in `index.d.cts`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (8): Last reviewed commit: "Merge remote-tracking branch 'origin/v1...." | Re-trigger Greptile

Comment thread lib/adapters/fetch.js Resolved
Comment thread index.d.ts Resolved
@jasonsaayman jasonsaayman added commit::fix The PR is related to a bugfix v1x Version 1 labels Sep 1, 2026
Comment thread lib/adapters/fetch.js Resolved
Comment thread index.d.ts Resolved
Comment thread index.d.ts Resolved
@vjymisal0

Copy link
Copy Markdown
Contributor Author

The only failing check I can see is Greptile Review, with no actionable code failure in the public status. Happy to adjust if a reviewer has a concrete finding.

@jasonsaayman jasonsaayman changed the title fix(fetch): unmask AxiosError on maxContentLength streaming violation and fix Response types fix(fetch): preserve response size errors across runtime wrappers Sep 13, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 9 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread PRE_RELEASE_DOCS.md Resolved
@jasonsaayman
jasonsaayman force-pushed the fix/fetch-adapter-max-length-error-unmasking branch from 2bcabed to f9f2949 Compare September 13, 2026 17:45
@greptile-apps

greptile-apps Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

…-length-error-unmasking

# Conflicts:
#	PRE_RELEASE_CHANGELOG.md
@jasonsaayman
jasonsaayman merged commit 56a5f1a into axios:v1.x Sep 16, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::fix The PR is related to a bugfix v1x Version 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants