Skip to content

fix(sdk): honor nullable return type in getSpotMarketAccount#2188

Open
shubhamessier wants to merge 1 commit into
velocity-exchange:masterfrom
shubhamessier:fix/sdk-get-spot-market-account-null-safety
Open

fix(sdk): honor nullable return type in getSpotMarketAccount#2188
shubhamessier wants to merge 1 commit into
velocity-exchange:masterfrom
shubhamessier:fix/sdk-get-spot-market-account-null-safety

Conversation

@shubhamessier

@shubhamessier shubhamessier commented Jun 6, 2026

Copy link
Copy Markdown

driftClient.getSpotMarketAccount() and forceGetSpotMarketAccount() are declared to return SpotMarketAccount | undefined, but currently dereference .data on the underlying DataAndSlot<...> | undefined returned by accountSubscriber.

This causes a TypeError when the requested marketIndex is not present in the subscriber cache.

Use optional chaining when accessing .data so the implementation matches the declared return type and correctly returns undefined when the account is unavailable.

This ensures external consumers can safely handle the nullable return path without encountering runtime exceptions.

Closes #2137.

Summary by CodeRabbit

Bug Fixes

  • Improved error handling in spot market account retrieval methods to safely handle edge cases where market lookups may return undefined, preventing potential runtime failures.

`driftClient.getSpotMarketAccount()` and `forceGetSpotMarketAccount()` are declared to return `SpotMarketAccount | undefined`, but currently dereference `.data` on the underlying `DataAndSlot<...> | undefined` returned by `accountSubscriber`.

This causes a `TypeError` when the requested `marketIndex` is not present in the subscriber cache.

Use optional chaining when accessing `.data` so the implementation matches the declared return type and correctly returns `undefined` when the account is unavailable.

This ensures external consumers can safely handle the nullable return path without encountering runtime exceptions.

Closes velocity-exchange#2137.
@coderabbitai

coderabbitai Bot commented Jun 6, 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: 49cf659b-089f-4f9d-b79f-6c49c258cc22

📥 Commits

Reviewing files that changed from the base of the PR and between 0ae3e3b and 5e26f41.

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

Walkthrough

DriftClient.getSpotMarketAccount and DriftClient.forceGetSpotMarketAccount now defensively handle undefined subscriber lookups by using optional chaining (?.data) instead of direct property access, preventing runtime errors when the account subscriber returns no value.

Changes

Spot market account lookup safety

Layer / File(s) Summary
Optional chaining for spot market lookups
sdk/src/driftClient.ts
Both getSpotMarketAccount and forceGetSpotMarketAccount add optional chaining (?.) when accessing .data on getSpotMarketAccountAndSlot(marketIndex) to safely return undefined when the subscriber lookup fails instead of throwing a runtime error.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐰 A rabbit hops through the code with care,
Optional chains now guard everywhere—
No more crashes from undefined dreams,
Just safe returns and cleaner streams.
Drift client smiles at the simple fix,
Safety's sweet in the smallest mix! 🌙

🚥 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 clearly and specifically describes the primary change: fixing nullable return type handling in getSpotMarketAccount by using optional chaining.
Linked Issues check ✅ Passed The pull request directly addresses issue #2137 by adding optional chaining to accountSubscriber calls as requested, allowing safe undefined returns.
Out of Scope Changes check ✅ Passed All changes are focused on the requested null-safety improvements in getSpotMarketAccount and forceGetSpotMarketAccount methods.
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.


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.

@shubhamessier

Copy link
Copy Markdown
Author

Hey @lowkeynicc can you kindly review the changes once, thanks!

cc: @LukasDeco

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