Skip to content

Global fetch produces unhelpful Error for ENOTFOUND #42804

@kevinoid

Description

@kevinoid

Version

v18.0.0

Platform

Linux kevinolos 5.18.0-rc3 #197 SMP PREEMPT_DYNAMIC Mon Apr 18 07:08:40 MDT 2022 x86_64 GNU/Linux

Subsystem

http

What steps will reproduce the bug?

Run node -e "fetch('http://invalid')"

How often does it reproduce? Is there a required condition?

100% reliable.

What is the expected behavior?

A helpful error, such as the one produced by undici:

Error: getaddrinfo ENOTFOUND invalid.
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:71:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'invalid'
}

What do you see instead?

An error indicating that fetch failed with a cause of Error: [object Object]:

TypeError: fetch failed
    at Object.processResponse (node:internal/deps/undici/undici:7188:34)
    at node:internal/deps/undici/undici:7516:42
    at node:internal/process/task_queues:140:7
    at AsyncResource.runInAsyncScope (node:async_hooks:202:9)
    at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: Error: [object Object]
      at makeNetworkError (node:internal/deps/undici/undici:6317:51)
      at httpNetworkFetch (node:internal/deps/undici/undici:7810:16)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async httpNetworkOrCacheFetch (node:internal/deps/undici/undici:7703:33)
      at async httpFetch (node:internal/deps/undici/undici:7557:37)
      at async schemeFetch (node:internal/deps/undici/undici:7489:18)
      at async node:internal/deps/undici/undici:7342:20
      at async mainFetch (node:internal/deps/undici/undici:7338:20) {
    [cause]: undefined
  }
}

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    fetchIssues and PRs related to the Fetch API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions