Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no stacktrace #1736

Closed
2 tasks done
joshxyzhimself opened this issue Jun 1, 2021 · 4 comments
Closed
2 tasks done

no stacktrace #1736

joshxyzhimself opened this issue Jun 1, 2021 · 4 comments

Comments

@joshxyzhimself
Copy link

Describe the bug

  • Node.js version: 16.2
  • OS & version: ubuntu 20.04

Actual behavior

It has no stacktrace, you know those that when you click takes you to the lines of code that led to that error

HTTPError: Response code 500 (Internal Server Error)
    at Request.<anonymous> (/home/user/Documents/project/node_modules/got/dist/source/as-promise/index.js:117:42)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: undefined,
  timings: {
    start: 1622538853719,
    socket: 1622538853721,
    lookup: 1622538853792,
    connect: 1622538853824,
    secureConnect: 1622538853919,
    upload: 1622538853919,
    response: 1622538854137,
    end: 1622538854138,
    error: undefined,
    abort: undefined,
    phases: {
      wait: 2,
      dns: 71,
      tcp: 32,
      tls: 95,
      request: 0,
      firstByte: 218,
      download: 1,
      total: 419
    }
  }
}

Expected behavior

It has stacktrace

Code to reproduce

try {
  // any got request
} catch (e) {
  console.error(e);
  throw e;
}

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@joshxyzhimself
Copy link
Author

joshxyzhimself commented Jun 1, 2021

e.stack is just

HTTPError: Response code 500 (Internal Server Error)
    at Request.<anonymous> (/home/user/Documents/project/node_modules/got/dist/source/as-promise/index.js:117:42)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

anyone know where the correct stacktrace is stored?


for illustration purposes, the following code correctly tells me that the source of the error was the await line at at line 3.

process.nextTick(async () => {
  try {
    await new Promise((resolve, reject) => setTimeout(() => reject(new Error('Test error.')), 1));
  } catch (e) {
    console.error(e);
  }
});
user@device:~/Documents/user$ node ./test.js
Error: Test error.
    at Timeout._onTimeout (/home/jxyz/Documents/user/test.js:3:68)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)

is got intentionally eating those errors / stacktraces?

@joshxyzhimself
Copy link
Author

This is really hard to work with, good lord.

@joshxyzhimself joshxyzhimself reopened this Jun 4, 2021
@joshxyzhimself joshxyzhimself reopened this Jun 4, 2021
@szmarczak szmarczak reopened this Jun 4, 2021
Repository owner locked and limited conversation to collaborators Jun 4, 2021
@szmarczak
Copy link
Collaborator

for illustration purposes, the following code correctly tells me that the source of the error was the await line at at line 3.

Node.js ate the trace where the promise was called as well. Same happens in Got, we can do nothing about it.

The error is created in dist/source/as-promise/index.js, line 117.


In the v11 branch:

diff --git a/source/core/index.ts b/source/core/index.ts
index 084d0a3..22a0d81 100644
--- a/source/core/index.ts
+++ b/source/core/index.ts
@@ -2159,6 +2159,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
                        this.push(null);
                });
 
+               console.log('core', new Error().stack);
                this.emit('response', response);
 
                for (const destination of this[kServerResponsesPiped]) {
diff --git a/source/as-promise/index.ts b/source/as-promise/index.ts
index efd9470..34d6f54 100644
--- a/source/as-promise/index.ts
+++ b/source/as-promise/index.ts
@@ -125,6 +125,7 @@ export default function asPromise<T>(normalizedOptions: NormalizedOptions): Canc
                                }
 
                                if (!isResponseOk(response)) {
+                                       console.log('promise', new Error().stack);
                                        request._beforeError(new HTTPError(response));
                                        return;
                                }
core Error
    at Request._onResponseBase (/home/szm/Desktop/got/dist/source/core/index.js:916:29)
    at Request._onResponse (/home/szm/Desktop/got/dist/source/core/index.js:935:24)
    at ClientRequest.<anonymous> (/home/szm/Desktop/got/dist/source/core/index.js:949:23)
    at Object.onceWrapper (node:events:485:26)
    at ClientRequest.emit (node:events:390:22)
    at ClientRequest.origin.emit (/home/szm/Desktop/got/node_modules/@szmarczak/http-timer/dist/source/index.js:39:20)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:636:27)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:129:17)
    at TLSSocket.socketOnData (node:_http_client:502:22)
    at TLSSocket.emit (node:events:378:20)
promise Error
    at Request.<anonymous> (/home/szm/Desktop/got/dist/source/as-promise/index.js:117:44)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

core is called right before emitting response, and promise is called when the response handler is executed.

@szmarczak
Copy link
Collaborator

Duplicate of #1077

@szmarczak szmarczak marked this as a duplicate of #1077 Jun 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants