Skip to content

Fix type safety and error handling in parallel balance check#1042

Merged
ebma merged 2 commits into
add-parallel-checks-squidrouterpayfrom
copilot/sub-pr-1041
Jan 26, 2026
Merged

Fix type safety and error handling in parallel balance check#1042
ebma merged 2 commits into
add-parallel-checks-squidrouterpayfrom
copilot/sub-pr-1041

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 26, 2026

Addresses code review feedback on the parallel balance check optimization for SquidRouter phase handler.

Type Safety

  • quote.outputCurrency: as anyas FiatToken
  • balanceCheckPromise: Promise<any>Promise<Big>
  • Added isEvmNetwork() type guard to validate destination before EVM balance checks

Error Handling

  • Wrapped Promise.any() inputs with .catch() to prevent unhandled rejections when the losing promise rejects after winner resolves
  • Rejected promises now use Error objects instead of plain strings
  • Distinguish BalanceCheckError types in failure messages:
    • Timeout: Expected behavior when bridge is slow
    • ReadFailure: Unexpected infrastructure issue
// Before: Both errors treated identically
throw new Error(`Both checks failed. Errors: ${errors.join(", ")}`);

// After: Meaningful distinction
if (balanceError.type === BalanceCheckErrorType.Timeout) {
  errorMessage += ` Balance check timed out after ${timeout}ms.`;
} else if (balanceError.type === BalanceCheckErrorType.ReadFailure) {
  errorMessage += ` Balance check read failure (unexpected infrastructure issue): ${msg}.`;
}

Documentation

  • Documented 15-minute timeout rationale (vs 3-5 minutes in other handlers): cross-chain settlement and gas payment legitimately take longer under network congestion

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@netlify
Copy link
Copy Markdown

netlify Bot commented Jan 26, 2026

Deploy Preview for vortex-sandbox ready!

Name Link
🔨 Latest commit c47073a
🔍 Latest deploy log https://app.netlify.com/projects/vortex-sandbox/deploys/6977ce05cf4fd000085b7e3c
😎 Deploy Preview https://deploy-preview-1042--vortex-sandbox.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

- Add BalanceCheckError imports for proper error handling
- Document 15-minute timeout rationale for bridge flows
- Add isEvmNetwork type guard to validate EVM destinations
- Fix type safety: balanceCheckPromise is Promise<Big>
- Fix type safety: quote.outputCurrency as FiatToken
- Use Error objects for rejected promises
- Fix typo in comment (double space)
- Handle Promise.any unhandled rejections with .catch()
- Distinguish BalanceCheckError timeout vs read failure in error messages

Co-authored-by: ebma <6690623+ebma@users.noreply.github.com>
Copilot AI changed the title [WIP] Add parallel balance check optimization to SquidRouter Fix type safety and error handling in parallel balance check Jan 26, 2026
Copilot AI requested a review from ebma January 26, 2026 20:29
@ebma ebma marked this pull request as ready for review January 26, 2026 20:31
@ebma ebma merged commit 7ac8fda into add-parallel-checks-squidrouterpay Jan 26, 2026
4 checks passed
@ebma ebma deleted the copilot/sub-pr-1041 branch January 26, 2026 20:31
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

Successfully merging this pull request may close these issues.

2 participants