From 625859d06e727ce712e9934829952817d9f7d019 Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Wed, 23 Oct 2024 18:03:44 -0700 Subject: [PATCH] Log unknown swap errors --- src/core/swap/swap-api.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/core/swap/swap-api.ts b/src/core/swap/swap-api.ts index 74b92024..5a5722c3 100644 --- a/src/core/swap/swap-api.ts +++ b/src/core/swap/swap-api.ts @@ -76,6 +76,23 @@ export async function fetchSwapQuotes( error => { pendingIds.delete(pluginId) log.warn(`${pluginId} gave swap error: ${String(error)}`) + // Log unknown errors: + if (isUnknownSwapError(error)) { + log.crash(`Unknown swap error: ${String(error)}`, { + error, + swapPluginId: pluginId, + request: { + // Stringify to include "null" + fromToken: String(request.fromTokenId), + fromWalletType: request.fromWallet.type, + // Stringify to include "null" + toToken: String(request.toTokenId), + toWalletType: request.toWallet.type, + // toWalletType: request.fromWallet.type, + quoteFor: request.quoteFor + } + }) + } throw error } ) @@ -232,3 +249,14 @@ function rankError(error: unknown): number { if (asMaybeSwapCurrencyError(error) != null) return 2 return 1 } + +function isUnknownSwapError(error: unknown): boolean { + return ( + asMaybeInsufficientFundsError(error) == null && + asMaybePendingFundsError(error) == null && + asMaybeSwapAboveLimitError(error) == null && + asMaybeSwapBelowLimitError(error) == null && + asMaybeSwapPermissionError(error) == null && + asMaybeSwapCurrencyError(error) == null + ) +}