Skip to content

getVAAWithRetries throws outside of try/catch block. #778

@orion-wilson

Description

@orion-wilson
  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)
        });
    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions