From 19502d2d13a2f3e950ecc93f292c76f7f9fbf717 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 8 May 2024 18:53:44 +0200 Subject: [PATCH 1/2] fetch: fix captureStackTrace --- index-fetch.js | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index-fetch.js b/index-fetch.js index a5903f1a8cb..da07e5489a8 100644 --- a/index-fetch.js +++ b/index-fetch.js @@ -7,7 +7,7 @@ const fetchImpl = require('./lib/web/fetch').fetch module.exports.fetch = function fetch (resource, init = undefined) { return fetchImpl(resource, init).catch((err) => { if (err && typeof err === 'object') { - Error.captureStackTrace(err, this) + Error.captureStackTrace(err, fetch) } throw err }) diff --git a/index.js b/index.js index fee89ec57bb..512c20241f9 100644 --- a/index.js +++ b/index.js @@ -108,7 +108,7 @@ module.exports.fetch = async function fetch (init, options = undefined) { return await fetchImpl(init, options) } catch (err) { if (err && typeof err === 'object') { - Error.captureStackTrace(err, this) + Error.captureStackTrace(err, fetch) } throw err From c20ffe2d19192b7892f82d12d3c2953ea2c0b1e8 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Wed, 8 May 2024 19:44:16 +0200 Subject: [PATCH 2/2] improve test case performance --- index-fetch.js | 2 +- index.js | 2 +- test/fetch/client-error-stack-trace.js | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/index-fetch.js b/index-fetch.js index da07e5489a8..01df32d2fb4 100644 --- a/index-fetch.js +++ b/index-fetch.js @@ -7,7 +7,7 @@ const fetchImpl = require('./lib/web/fetch').fetch module.exports.fetch = function fetch (resource, init = undefined) { return fetchImpl(resource, init).catch((err) => { if (err && typeof err === 'object') { - Error.captureStackTrace(err, fetch) + Error.captureStackTrace(err) } throw err }) diff --git a/index.js b/index.js index 512c20241f9..dd5ada84bc6 100644 --- a/index.js +++ b/index.js @@ -108,7 +108,7 @@ module.exports.fetch = async function fetch (init, options = undefined) { return await fetchImpl(init, options) } catch (err) { if (err && typeof err === 'object') { - Error.captureStackTrace(err, fetch) + Error.captureStackTrace(err) } throw err diff --git a/test/fetch/client-error-stack-trace.js b/test/fetch/client-error-stack-trace.js index ddc7f4d25cf..146443bc077 100644 --- a/test/fetch/client-error-stack-trace.js +++ b/test/fetch/client-error-stack-trace.js @@ -2,9 +2,14 @@ const { test } = require('node:test') const assert = require('node:assert') -const { fetch } = require('../..') +const { fetch, setGlobalDispatcher, Agent } = require('../..') const { fetch: fetchIndex } = require('../../index-fetch') +setGlobalDispatcher(new Agent({ + headersTimeout: 500, + connectTimeout: 500 +})) + test('FETCH: request errors and prints trimmed stack trace', async (t) => { try { await fetch('http://a.com')