]> git.codecow.com Git - libnemo.git/commitdiff
Restore try-catch on unexpectedly-invalid batch responses.
authorChris Duncan <chris@codecow.com>
Wed, 12 Aug 2026 00:17:16 +0000 (17:17 -0700)
committerChris Duncan <chris@codecow.com>
Wed, 12 Aug 2026 00:17:16 +0000 (17:17 -0700)
src/lib/rpc/accounts_balances.ts
src/lib/rpc/accounts_frontiers.ts
src/lib/rpc/blocks_info.ts

index 7a0a9b2fe198e459560b09f9f813ab8e252a551a..0704c4ea0fbfaf671a166c818bb7bd5fb052e7e2 100644 (file)
@@ -33,7 +33,13 @@ export function accounts_balances (body: unknown): AccountsBalancesResponse {
                        response.balances = balances
                        for (const [address, data] of Object.entries(body.balances) as [string, unknown][]) {
                                if (Account.isValid(address)) {
-                                       balances[address] = account_balance(data)
+                                       try {
+                                               balances[address] = account_balance(data)
+                                       } catch (err: any) {
+                                               const errors = response.errors ?? Object.create(null)
+                                               response.errors = errors
+                                               errors[address] = err?.message ?? 'Invalid account balance'
+                                       }
                                }
                        }
                }
index 9eb6fc7b99777b472fe4cc14a7c1b09a20f8f310..7d1aa5bc9eedd06dbb7dc791290da20b8bd1a487 100644 (file)
@@ -33,7 +33,13 @@ export function accounts_frontiers (body: unknown): AccountsFrontiersResponse {
                        response.frontiers = frontiers
                        for (const [address, frontier] of Object.entries(body.frontiers) as [string, unknown][]) {
                                if (Account.isValid(address) && hex.is(frontier, 64)) {
-                                       frontiers[address] = frontier
+                                       try {
+                                               frontiers[address] = frontier
+                                       } catch (err: any) {
+                                               const errors = response.errors ?? Object.create(null)
+                                               response.errors = errors
+                                               errors[address] = err?.message ?? 'Invalid account balance'
+                                       }
                                }
                        }
                }
index 7d59f61d2e8cc9296135d816f863dd0e8d7f4384..94ae905b5507f26981446966101845eb930a8f70 100644 (file)
@@ -56,7 +56,13 @@ export function blocks_info (body: unknown): BlocksInfoResponse {
                        response.blocks = blocks
                        for (const [hash, data] of Object.entries(body.blocks) as [string, unknown][]) {
                                if (hex.is(hash, 64)) {
-                                       blocks[hash] = block_info(data)
+                                       try {
+                                               blocks[hash] = block_info(data)
+                                       } catch (err: any) {
+                                               const errors = response.errors ?? Object.create(null)
+                                               response.errors = errors
+                                               errors[hash] = err?.message ?? 'Invalid block'
+                                       }
                                }
                        }
                }