Skip to content

fix: add optional chaining to spot market account retrievals - #2191

Open
HkSolDev wants to merge 1 commit into
velocity-exchange:masterfrom
HkSolDev:fix-optional-chaining
Open

fix: add optional chaining to spot market account retrievals#2191
HkSolDev wants to merge 1 commit into
velocity-exchange:masterfrom
HkSolDev:fix-optional-chaining

Conversation

@HkSolDev

@HkSolDev HkSolDev commented Jun 15, 2026

Copy link
Copy Markdown

Add optional chaining to getSpotMarketAccount and forceGetSpotMarketAccount to prevent potential runtime errors if the account subscriber has not yet loaded the slot data.

Closes #2137

Summary by CodeRabbit

  • Bug Fixes
    • Improved robustness by gracefully handling missing spot market subscriber data, preventing errors when data is unavailable.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 18d8ec7b-a7b6-4717-a564-e234943e637b

📥 Commits

Reviewing files that changed from the base of the PR and between 0ae3e3b and 20135a7.

📒 Files selected for processing (1)
  • sdk/src/driftClient.ts

Walkthrough

Both getSpotMarketAccount and forceGetSpotMarketAccount in DriftClient now apply optional chaining (?.data) to the result of getSpotMarketAccountAndSlot(marketIndex), returning undefined instead of throwing when subscriber data is absent.

Changes

Spot Market Getter Null Safety

Layer / File(s) Summary
Optional chaining on spot market account getters
sdk/src/driftClient.ts
getSpotMarketAccount and forceGetSpotMarketAccount both switch from .data to ?.data on the getSpotMarketAccountAndSlot call result, gracefully returning undefined when no account data is present.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 A dot and a question mark, small but wise,
No more hard crashes before our eyes.
When the account is missing, we gently return,
undefined instead of a runtime concern.
Optional chaining — the bunny-approved way! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: add optional chaining to spot market account retrievals' accurately summarizes the main change—adding optional chaining to spot market account getter methods.
Linked Issues check ✅ Passed The changes directly address issue #2137 by implementing optional chaining on getSpotMarketAccountAndSlot(marketIndex).data calls in both getter methods as requested.
Out of Scope Changes check ✅ Passed All changes are scoped to the specific objective of adding optional chaining to spot market account retrievals in driftClient.ts, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed due to a network error.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minor driftClient improvement

1 participant