-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update BlockTable.getLatest to throw an error and simplify logic #915
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,7 +290,7 @@ describe('helpers', () => { | |
latestBlock, | ||
]: [ | ||
SubaccountFromDatabase | undefined, | ||
BlockFromDatabase | undefined, | ||
BlockFromDatabase, | ||
] = await Promise.all([ | ||
SubaccountTable.findById(testConstants.defaultSubaccountId), | ||
BlockTable.getLatest(), | ||
Comment on lines
290
to
296
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script output indicates that there is still a check for No output was produced for the Based on the provided information, the following issue has been identified:
Analysis chainThe change to the Scripts ExecutedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Verify that all usages of `latestBlock` handle the new error-throwing behavior.
rg --type ts "latestBlock" --context 5
Length of output: 40307 Script: #!/bin/bash
# Check for the presence of 'undefined' checks related to 'latestBlock' in the specified files
# and ensure they have been replaced with error handling.
# Check in perpetual-positions-controller.ts
echo "Checking perpetual-positions-controller.ts"
rg "latestBlock === undefined" "indexer/services/comlink/src/controllers/api/v4/perpetual-positions-controller.ts"
# Check in asset-positions-controller.ts
echo "Checking asset-positions-controller.ts"
rg "latestBlock === undefined" "indexer/services/comlink/src/controllers/api/v4/asset-positions-controller.ts"
# Check in addresses-controller.ts
echo "Checking addresses-controller.ts"
rg "latestBlock === undefined" "indexer/services/comlink/src/controllers/api/v4/addresses-controller.ts"
Length of output: 654 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ class AddressesController extends Controller { | |
): Promise<SubaccountResponseObject[]> { | ||
// TODO(IND-189): Use a transaction across all the DB queries | ||
const [subaccounts, latestBlock]: | ||
[SubaccountFromDatabase[], BlockFromDatabase | undefined] = await Promise.all([ | ||
[SubaccountFromDatabase[], BlockFromDatabase] = await Promise.all([ | ||
SubaccountTable.findAll( | ||
{ | ||
Comment on lines
82
to
87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Analysis chainThe change in the Scripts ExecutedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for any remaining checks for `latestBlock` being undefined.
rg --type ts "latestBlock\s*?==\s*?undefined"
Length of output: 47 Script: #!/bin/bash
# Search for a broader pattern of checks involving `latestBlock` and `undefined`.
rg --type ts "latestBlock\s*?[=!]==?\s*?undefined"
Length of output: 288 Script: #!/bin/bash
# Check the context of the lines where `latestBlock` is being checked against `undefined`.
rg --type ts -C 3 "latestBlock\s*?[=!]==?\s*?undefined" indexer/services/comlink/src/controllers/api/v4/perpetual-positions-controller.ts
rg --type ts -C 3 "latestBlock\s*?[=!]==?\s*?undefined" indexer/packages/postgres/src/stores/block-table.ts
Length of output: 746 |
||
address, | ||
|
@@ -92,7 +92,7 @@ class AddressesController extends Controller { | |
BlockTable.getLatest(), | ||
]); | ||
|
||
if (subaccounts.length === 0 || latestBlock === undefined) { | ||
if (subaccounts.length === 0) { | ||
throw new NotFoundError(`No subaccounts found for address ${address}`); | ||
} | ||
|
||
|
@@ -175,7 +175,7 @@ class AddressesController extends Controller { | |
AssetPositionFromDatabase[], | ||
AssetFromDatabase[], | ||
MarketFromDatabase[], | ||
BlockFromDatabase | undefined, | ||
BlockFromDatabase, | ||
] = await Promise.all([ | ||
SubaccountTable.findById( | ||
subaccountId, | ||
|
@@ -197,7 +197,7 @@ class AddressesController extends Controller { | |
BlockTable.getLatest(), | ||
]); | ||
|
||
if (subaccount === undefined || latestBlock === undefined) { | ||
if (subaccount === undefined) { | ||
throw new NotFoundError( | ||
`No subaccount found with address ${address} and subaccountNumber ${subaccountNumber}`, | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The addition of a try-catch block for error handling in
runFuncWithTimingStat
is a good practice for capturing errors during the execution of thepromise
. However, thestats.timing
call is duplicated in both the catch block and after the try-catch block. Consider refactoring to avoid this duplication and ensure that timing stats are recorded whether an error occurs or not.Committable suggestion