Skip to content

Commit

Permalink
Some more sentry noise fixes (#1151)
Browse files Browse the repository at this point in the history
* chore: add regex patterns for errors to ignore in sentry config

* fix: handle unhandled promise rejection in substrate connections

* fix: revert last and make throwAfter reject with a real Error object

* fix: catch and emit error in websocket connection, when response is not JSON

* chore: changeset

* fix: handle error states arising from change to throwAfter function

* fix: improve error handling in Websocket

* chore: changeset
  • Loading branch information
chidg authored Nov 13, 2023
1 parent 072b7c9 commit e0eb84a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-toys-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@talismn/chain-connector": patch
---

Improved error handling in Websocket connector
6 changes: 6 additions & 0 deletions .changeset/quiet-papayas-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@talismn/chain-connector": patch
"@talismn/util": patch
---

Error handling improvements
4 changes: 4 additions & 0 deletions apps/extension/src/core/config/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const initSentry = (sentry: typeof SentryBrowser | typeof SentryReact) =>
release: process.env.RELEASE,
sampleRate: 1,
maxBreadcrumbs: 20,
ignoreErrors: [
/(No window with id: )(\d+).?/,
/(disconnected from wss)[(]?:\/\/[\w./:-]+: \d+:: Normal Closure[)]?/,
],
// prevents sending the event if user has disabled error tracking
beforeSend: async (event) => ((await firstValueFrom(useErrorTracking)) ? event : null),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
1 change: 1 addition & 0 deletions apps/extension/src/core/domains/ethereum/handler.tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ export class EthTabsHandler extends TabsHandler {
client.request({ method: "eth_chainId" }),
throwAfter(10_000, "timeout"), // 10 sec timeout
])
assert(!!rpcChainIdHex, `No chainId returned for ${rpcUrl}`)
const rpcChainId = hexToNumber(rpcChainIdHex)

assert(rpcChainId === chainId, "chainId mismatch")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { log } from "@core/log"
import { createNotification } from "@core/notifications"
import { chainConnectorEvm } from "@core/rpcs/chain-connector-evm"
import { chaindataProvider } from "@core/rpcs/chaindata"
import { assert } from "@polkadot/util"
import * as Sentry from "@sentry/browser"
import { EvmNetworkId } from "@talismn/chaindata-provider"
import { sleep, throwAfter } from "@talismn/util"
Expand Down Expand Up @@ -57,6 +58,7 @@ export const watchEthereumTransaction = async (
throwAfter(5 * 60_000, "Transaction not found"),
])

assert(receipt, "Transaction to watch not found")
// check hash which may be incorrect for cancelled tx, in which case receipt includes the replacement tx hash
if (receipt.transactionHash === hash) {
// to test failing transactions, swap on busy AMM pools with a 0.05% slippage limit
Expand Down
1 change: 1 addition & 0 deletions apps/extension/src/ui/hooks/ledger/useLedgerEthereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const useLedgerEthereum = (persist = false) => {
ledger.getAddress(getEthLedgerDerivationPath("LedgerLive")),
throwAfter(5_000, "Timeout"),
])

const { version } = await ledger.getAppConfiguration()
if (!gte(version, LEDGER_ETHEREUM_MIN_VERSION))
throw new LedgerError("Unsupported version", "UnsupportedVersion")
Expand Down
13 changes: 8 additions & 5 deletions packages/chain-connector/src/Websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,15 @@ export class Websocket implements ProviderInterface {

#onSocketMessage = (message: MessageEvent<string>): void => {
// log.debug(() => ["received", message.data])
try {
const response = JSON.parse(message.data) as UnknownJsonRpcResponse

const response = JSON.parse(message.data) as UnknownJsonRpcResponse

return isUndefined(response.method)
? this.#onSocketMessageResult(response)
: this.#onSocketMessageSubscribe(response)
return isUndefined(response.method)
? this.#onSocketMessageResult(response)
: this.#onSocketMessageSubscribe(response)
} catch (e) {
this.#emit("error", new Error("Invalid websocket message received", { cause: e }))
}
}

#onSocketMessageResult = (response: UnknownJsonRpcResponse): void => {
Expand Down
2 changes: 1 addition & 1 deletion packages/util/src/throwAfter.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const throwAfter = (ms: number, reason: string) =>
new Promise<never>((_, reject) => setTimeout(() => reject(reason), ms))
new Promise<void>((_, reject) => setTimeout(() => reject(new Error(reason)), ms))

0 comments on commit e0eb84a

Please sign in to comment.