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

getVAAWithRetries throws outside of try/catch block. #778

Open
orion-wilson opened this issue Jan 14, 2025 · 1 comment
Open

getVAAWithRetries throws outside of try/catch block. #778

orion-wilson opened this issue Jan 14, 2025 · 1 comment

Comments

@orion-wilson
Copy link

orion-wilson commented Jan 14, 2025

  const getVaa = async (initiatingChainId: number, initiatingHash: string) => {
    try {
      const wh = await getWh([initiatingChainId])
      const chainName = toChain(chainConfig[initiatingChainId].portalChainId)
      const srcChain = wh.getChain(chainName)
      const [whm] = await srcChain.parseTransaction(initiatingHash)
      const vaa = await wh.getVaa(whm, 'TokenBridge:Transfer', 0)

      if (!vaa) {
        return null
      }
      return vaa
    } catch (e: Error) {
      return e
    }
  }

Above fn is a slightly simplified version of one from my codebase

When the wormholescan API was down the other day this was throwing an uncaught exception after calling wh.getVaa and crashing the entire app. Chased it down with the debugger a little bit by modifying the url in node_modules to throw a similar exception.

Appears that something about the retry function is causing this error to happen outside the scope of this try.catch block. If I modify this in the tasks file to have a catch block (as below) it begins to be handled.

export async function retry(task, interval, timeout = DEFAULT_TASK_TIMEOUT, title) {
    const maxRetries = Math.floor(timeout / interval);
    let retries = 0;
    return new Promise((resolve, reject) => {
        task().then((result) => {
            if (result !== null) {
                resolve(result);
                return;
            }
            let intervalId = setInterval(async () => {
                if (retries >= maxRetries) {
                    clearInterval(intervalId);
                    resolve(null);
                    return;
                }
                const result = await task();
                if (result !== null) {
                    clearInterval(intervalId);
                    resolve(result);
                }
                else if (title) {
                    console.log(`Retrying ${title}, attempt ${retries}/${maxRetries} `);
                }
                retries++;
            }, interval);
        }).catch((e) => {
            reject(e)
        });
    });
}
@orion-wilson orion-wilson changed the title GetVAA throws outside of try/catch block. getVAAWithRetries throws outside of try/catch block. Jan 14, 2025
@orion-wilson
Copy link
Author

This solution clearly does not cause any retrying to happen, just there for illustration of the issue.

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