From 5d274b90b62ab4e4f87548de8d1c88d66c88b8dc Mon Sep 17 00:00:00 2001 From: Skillz Date: Wed, 23 Sep 2020 18:17:20 -0400 Subject: [PATCH] async stack trace capturing!!!!!!!!!!!!!!! --- src/module/requestManager.ts | 23 +++++++++++++++++++---- src/types/options.ts | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/module/requestManager.ts b/src/module/requestManager.ts index bea0086cb..816d57e69 100644 --- a/src/module/requestManager.ts +++ b/src/module/requestManager.ts @@ -197,6 +197,9 @@ async function runMethod( }, ); + const errorStack = new Error("Location In Your Files:"); + Error.captureStackTrace(errorStack); + return new Promise((resolve, reject) => { const callback = async () => { try { @@ -227,7 +230,7 @@ async function runMethod( }, ); const bucketIDFromHeaders = processHeaders(url, response.headers); - handleStatusCode(response); + handleStatusCode(response, errorStack); // Sometimes Discord returns an empty 204 response that can't be made to JSON. if (response.status === 204) return resolve(); @@ -238,6 +241,12 @@ async function runMethod( json.message === "You are being rate limited." ) { if (retryCount > 10) { + eventHandlers.debug?.( + { + type: "error", + data: { method, url, body, retryCount, bucketID, errorStack }, + }, + ); throw new Error(Errors.RATE_LIMIT_RETRY_MAXED); } @@ -258,8 +267,8 @@ async function runMethod( } catch (error) { eventHandlers.debug?.( { - type: "requestManagerFailed", - data: { method, url, body, retryCount, bucketID }, + type: "error", + data: { method, url, body, retryCount, bucketID, errorStack }, }, ); return reject(error); @@ -278,7 +287,7 @@ async function runMethod( }); } -function handleStatusCode(response: Response) { +function handleStatusCode(response: Response, errorStack?: unknown) { const status = response.status; if ( @@ -288,6 +297,12 @@ function handleStatusCode(response: Response) { return true; } + eventHandlers.debug?.( + { + type: "error", + data: { errorStack }, + }, + ); console.error(response); switch (status) { diff --git a/src/types/options.ts b/src/types/options.ts index a44519fee..410780aaf 100644 --- a/src/types/options.ts +++ b/src/types/options.ts @@ -56,10 +56,10 @@ export interface DebugArg { /** Red is for errors or urgent issues. Yellow is for warnings/alerts. Green is for actions being taken. Blue is for */ type?: | "identifying" + | "error" | "requestManager" | "globallyRateLimited" | "requestManagerSuccess" - | "requestManagerFailed" | "requestManagerFetching" | "requestManagerFetched" | "requestMembersProcessing"