question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The line where fetch is called doesn't show in the stack trace

See original GitHub issue

Version

v18.7.0

Platform

Linux 98a94d978874 5.4.0-122-generic nodejs/node#138~18.04.1-Ubuntu SMP Fri Jun 24 14:14:03 UTC 2022 x86_64 Linux

Subsystem

fetch

What steps will reproduce the bug?

async function a() {
    await fetch('http://a.com')
}

(async function() {
    await a()
    // → 🎉
}());

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

Always

What is the expected behavior?

At some point in the stack frame:

 at a (/home/user/projectA/a.js:8:11)

What do you see instead?

TypeError: fetch failed
    at Object.processResponse (node:internal/deps/undici/undici:7175:34)
    at Fetch.fetchFinale (node:internal/deps/undici/undici:7505:21)
    at Fetch.mainFetch (node:internal/deps/undici/undici:7399:21)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  cause: Error: getaddrinfo ENOTFOUND a.com
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:82:26) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'a.com'
  }
}

Additional information

Maybe undici issue @mcollina ?

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
mcollinacommented, Aug 11, 2022

I don’t think it would. This will get us there:

diff --git a/index.js b/index.js
index 8099f5a..0b9a2e5 100644
--- a/index.js
+++ b/index.js
@@ -92,7 +92,12 @@ if (nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 8)) {
       fetchImpl = require('./lib/fetch')
     }
     const dispatcher = (arguments[1] && arguments[1].dispatcher) || getGlobalDispatcher()
-    return fetchImpl.apply(dispatcher, arguments)
+    try {
+      return await fetchImpl.apply(dispatcher, arguments)
+    } catch (err) {
+      Error.captureStackTrace(err)
+      throw err
+    }
   }
   module.exports.Headers = require('./lib/fetch/headers').Headers
   module.exports.Response = require('./lib/fetch/response').Response

I’m not sure the exact implications of this.

cc @benjamingr

0reactions
mcollinacommented, Aug 23, 2022

@sosoba would you like to send a PR to implement this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do fetch errors not have a stacktrace in my single page ...
The problem is that network errors from fetch, caught in fetchArticles, do not contain a stack trace. So error.stack does not exist. Which...
Read more >
718760 - Show line number of fetch call in error stack trace
The error.stack in the above example doesn't show any line numbers, which seems a bit odd. Unless I'm misunderstanding, it should at least...
Read more >
traceback — Print or retrieve a stack traceback — Python 3.11 ...
The line is a string with leading and trailing whitespace stripped; if the source is not available it is None . traceback.extract_stack(f= ...
Read more >
Stack trace not showing correct line number - Google Groups
The problem is that the trace always gives us the first line of the method and not the line where the exception is...
Read more >
Analyze a stack trace - Android Developers
A stack trace shows a list of method calls that lead to the exception being thrown, together with the filenames and line numbers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found