From 8592600e8155b9219c256d365f2e2d7a32f907ac Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Mon, 29 May 2023 12:17:31 -0700 Subject: [PATCH] WIP avoid "Maximum call stack size exceeded" errors This is somewhat odd. I ran into the maximum call stack error and worked around it locally using this fix. But we do test for when the rate handler methods throw, so I am not sure what is up yet. I will get back to it --- src/index.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index e80f8f7e..1024517f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -92,9 +92,29 @@ export function throttling(octokit: Octokit, octokitOptions: OctokitOptions) { const events = {}; const emitter = new Bottleneck.Events(events); // @ts-expect-error - events.on("secondary-limit", state.onSecondaryRateLimit); + events.on("secondary-limit", async (...args) => { + try { + // @ts-expect-error + return await state.onSecondaryRateLimit(...args); + } catch (error) { + // avoid "Maximum call stack size exceeded" error + setTimeout(() => { + throw error; + }); + } + }); // @ts-expect-error - events.on("rate-limit", state.onRateLimit); + events.on("rate-limit", async (...args) => { + try { + // @ts-expect-error + return await state.onRateLimit(...args); + } catch (error) { + // avoid "Maximum call stack size exceeded" error + setTimeout(() => { + throw error; + }); + } + }); // @ts-expect-error events.on("error", (e) => octokit.log.warn("Error in throttling-plugin limit handler", e)