Skip to content

docs: fix code examples that crash at runtime and other inaccuracies#5386

Merged
mcollina merged 1 commit into
nodejs:mainfrom
AliMahmoudDev:fix/code-examples
Jun 7, 2026
Merged

docs: fix code examples that crash at runtime and other inaccuracies#5386
mcollina merged 1 commit into
nodejs:mainfrom
AliMahmoudDev:fix/code-examples

Conversation

@AliMahmoudDev
Copy link
Copy Markdown
Contributor

Fixes #5385

High severity

Dispatcher.md — DNS interceptor examples missing Agent import
Both DNS examples import Client but use new Agent(). Running these gives ReferenceError: Agent is not defined. Changed import to Agent.

H2CClient.md — await in non-async .then() callback
The example uses await inside .then(() => { which is a SyntaxError. Added async to the callback.

EnvHttpProxyAgent.md — Destructuring json from Response
Two examples destructure json from a fetch Response (const { status, json } = await fetch(...)), but json is a prototype method — destructuring yields undefined and await json() throws TypeError. Changed to use response.json().

Medium severity

Dispatcher.md — Retry example heading says "Redirect" (copy-paste)
Changed to "Basic Retry Interceptor".

Cookies.md — sameSite type says "String" not "Strict"

RetryHandler.md — retry callback return type wrong
Changed number | null to void to match implementation and RetryAgent.md.

Low severity

Fetch.md — Heading says Header not Headers

All changes verified against the actual source code.

Fixes nodejs#5385

- Dispatcher.md: fix DNS interceptor imports (Client -> Agent), fix retry example heading (Redirect -> Retry)
- H2CClient.md: add async to .then() callback to fix await SyntaxError
- EnvHttpProxyAgent.md: fix destructuring json from Response (use response.json())
- Cookies.md: fix sameSite type (String -> Strict)
- RetryHandler.md: fix retry callback return type (number|null -> void)
- Fetch.md: fix heading (Header -> Headers)
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.25%. Comparing base (8464ab7) to head (986b4cd).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5386   +/-   ##
=======================================
  Coverage   93.25%   93.25%           
=======================================
  Files         110      110           
  Lines       36752    36752           
=======================================
  Hits        34274    34274           
  Misses       2478     2478           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit ee59da3 into nodejs:main Jun 7, 2026
38 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 8, 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.

Code examples in docs that crash at runtime (imports, async, destructuring)

3 participants