]> git.codecow.com Git - libnemo.git/commitdiff
Fix possible undefined access.
authorChris Duncan <chris@codecow.com>
Sun, 9 Aug 2026 20:37:10 +0000 (13:37 -0700)
committerChris Duncan <chris@codecow.com>
Sun, 9 Aug 2026 20:37:10 +0000 (13:37 -0700)
src/lib/rpc/accounts_balances.ts
src/lib/rpc/accounts_frontiers.ts
src/lib/rpc/blocks_info.ts

index ebc90e096c9c002c83092b870e4a17106871d2a2..bce825a26b0957167a2a8aadc8cbcc4c5a5b65e2 100644 (file)
@@ -28,8 +28,9 @@ export function accounts_balances (body: unknown): AccountsBalancesResponse {
                                                throw new RpcError(error)
                                        }
                                } catch (err: any) {
-                                       response.errors ??= Object.create(null)
-                                       response.errors[address] = err?.message
+                                       const errors = response.errors ?? Object.create(null)
+                                       response.errors = errors
+                                       errors[address] = err?.message
                                }
                        }
                }
@@ -43,11 +44,13 @@ export function accounts_balances (body: unknown): AccountsBalancesResponse {
                                        if (data == null || typeof data !== 'object') {
                                                throw new RpcError('Invalid account balance data')
                                        }
-                                       response.balances ??= Object.create(null)
-                                       response.balances[address] = account_balance(data)
+                                       const balances = response.balances ?? Object.create(null)
+                                       response.balances = balances
+                                       balances[address] = account_balance(data)
                                } catch (err: any) {
-                                       response.errors ??= Object.create(null)
-                                       response.errors[address] ??= err?.message
+                                       const errors = response.errors ?? Object.create(null)
+                                       response.errors = errors
+                                       errors[address] = err?.message
                                }
                        }
                }
index 5b84d45a8dc7e072b3a63a12b7ec84466dac593f..173eae49952e63dfab79b2dcf36a56692cfa16dc 100644 (file)
@@ -30,12 +30,14 @@ export function accounts_frontiers (body: unknown): AccountsFrontiersResponse {
                                                throw new RpcError('Invalid account address')
                                        }
                                        if (hex.is(frontier, 64)) {
-                                               response.frontiers ??= Object.create(null)
-                                                                                               response.frontiers[address] = frontier
+                                               const frontiers = response.frontiers ?? Object.create(null)
+                                               response.frontiers = frontiers
+                                               frontiers[address] = frontier
                                        }
                                } catch (err: any) {
-                                       response.errors ??= Object.create(null)
-                                       response.errors[address] = err?.message
+                                       const errors = response.errors ?? Object.create(null)
+                                       response.errors = errors
+                                       errors[address] = err?.message
                                }
                        }
                }
@@ -52,8 +54,9 @@ export function accounts_frontiers (body: unknown): AccountsFrontiersResponse {
                                                throw new Error(error)
                                        }
                                } catch (err: any) {
-                                       response.errors ??= Object.create(null)
-                                       response.errors[address] = err?.message
+                                       const errors = response.errors ?? Object.create(null)
+                                       response.errors = errors
+                                       errors[address] = err?.message
                                }
                        }
                }
index 2260bffe189d0e57ca5974b2fa98b9013ed7a510..a5d088fd70729ff485c33f3a07920a3d15f845ac 100644 (file)
@@ -28,8 +28,9 @@ export function blocks_info (body: unknown): BlocksInfoResponse {
                                                throw new Error('Invalid blocks_info error')
                                        }
                                } catch (err: any) {
-                                       response.errors ??= Object.create(null)
-                                       response.errors[hash] = err?.message
+                                       const errors = response.errors ?? Object.create(null)
+                                       response.errors = errors
+                                       errors[address] = err?.message
                                }
                        }
                }
@@ -38,14 +39,16 @@ export function blocks_info (body: unknown): BlocksInfoResponse {
                        for (const [hash, data] of Object.entries(body.blocks) as [string, unknown][]) {
                                try {
                                        if (hex.is(hash)) {
-                                               response.blocks ??= Object.create(null)
-                                               response.blocks[hash] = block_info(data)
+                                               const blocks = response.blocks ?? Object.create(null)
+                                               response.blocks = blocks
+                                               blocks[hash] = block_info(data)
                                        } else {
                                                throw new Error('Invalid blocks_info hash')
                                        }
                                } catch (err: any) {
-                                       response.errors ??= Object.create(null)
-                                       response.errors[hash] ??= err?.message
+                                       const errors = response.errors ?? Object.create(null)
+                                       response.errors = errors
+                                       errors[address] = err?.message
                                }
                        }
                }