Open
Conversation
getPositionDetails panics when called with a closed/non-existent position ID. This is problematic for batch queries (get_positions_by_ids.cdc) - one stale ID causes the entire batch to fail. Refactor _borrowPosition to delegate to a new _tryBorrowPosition that returns an optional reference instead of panicking. Add tryGetPositionDetails that guards on existence before delegating to getPositionDetails. Update get_positions_by_ids.cdc to use tryGetPositionDetails so closed positions are silently skipped instead of failing the batch.
jordanschalm
previously approved these changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is done
getPositionDetailspanics when called with a closed/non-existent position ID.This is problematic for batch queries (
get_positions_by_ids.cdc) - one stale IDcauses the entire batch to fail.
Refactor
_borrowPositionto delegate to a new_tryBorrowPositionthat returnsan optional reference instead of panicking. Add
tryGetPositionDetailsthatguards on existence before delegating to
getPositionDetails.Update
get_positions_by_ids.cdcto usetryGetPositionDetailsso closed positionsare silently skipped instead of failing the batch.
Why
The fcm-observer queries positions in batches using get_positions_by_ids.cdc. Here's the problem:
get_position_ids.cdc-> get back[0, 3, 7, 12, ...]get_positions_by_ids.cdcwith those IDsgetPositionDetails(pid: 7)panics -> the entire batch fails, all 50 positions get no updateWe're always behind - by the time we use the IDs, some may already be stale.
tryGetPositionDetailsskips missing positions instead of panicking, so the rest of the batch succeeds.