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

Missing async trace in Node V12 #1484

Open
tsingyee opened this issue May 6, 2019 · 1 comment
Open

Missing async trace in Node V12 #1484

tsingyee opened this issue May 6, 2019 · 1 comment

Comments

@tsingyee
Copy link

tsingyee commented May 6, 2019

Node V12 supports full async stack trace, but superagent error stack still missing the outter async stack trace when there is error thrown from super agent, e.g a server 500 internal error.
Is there anything need to be fixed from superagent side to keep the async stack trace?

at Response.toError (C:\dev\LT\wise-report-center\node_modules\superagent\lib\node\response.js:98:13)
at ResponseBase._setStatusProperties (C:\dev\LT\wise-report-center\node_modules\superagent\lib\response-base.js:119:48)
at new Response (C:\dev\LT\wise-report-center\node_modules\superagent\lib\node\response.js:44:8)
at Request._emitResponse (C:\dev\LT\wise-report-center\node_modules\superagent\lib\node\index.js:909:18)
at C:\dev\LT\wise-report-center\node_modules\superagent\lib\node\index.js:1105:42
at IncomingMessage.<anonymous> (C:\dev\LT\wise-report-center\node_modules\superagent\lib\node\parsers\json.js:22:7)
at IncomingMessage.emit (events.js:201:15)
at endReadableNT (_stream_readable.js:1130:12)
at processTicksAndRejections (internal/process/task_queues.js:84:17)
@tsingyee
Copy link
Author

tsingyee commented May 6, 2019

I have a work around for now, manually keep the async stack trace before calling superagent, and add it back if necessary

let httpClient = {};
['get', 'post', 'delete', 'put'].forEach((method) => {
    let methodFn = superagent[method];
    httpClient[method] = async function (requestUrl, data, fn) {
        let responsePromise = methodFn.call(null, requestUrl, data, fn);
        let originalStack;
        try {
            throw new Error("original stack trace");
        } catch (e) {
            originalStack = e.stack;
        }
        try {
            let response = await responsePromise;
            return response.body;
        } catch (e) {
            e.fullStack = e.stack + originalStack;
            throw e;
        }
    };
});

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

No branches or pull requests

1 participant