Skip to content

feat(statics): add CoinMap.getOrUndefined() safe accessor#8937

Draft
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
masterfrom
cgd-255-coinmap-get-or-undefined
Draft

feat(statics): add CoinMap.getOrUndefined() safe accessor#8937
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
masterfrom
cgd-255-coinmap-get-or-undefined

Conversation

@bitgo-ai-agent-dev
Copy link
Copy Markdown

Summary

  • Add CoinMap.getOrUndefined(key) to @bitgo/statics — returns undefined for unknown coins instead of throwing CoinNotDefinedError
  • Refactor get() to delegate its lookup logic to getOrUndefined(), eliminating code duplication
  • Add unit tests covering: known key, unknown key, and lookup-by-id via getOrUndefined()

Context

Part of CGD-255 (CR-1388 action item). CoinMap.get() throws CoinNotDefinedError for unknown coins — optional-chaining (?.) provides no protection against thrown exceptions. This was the root cause of the CR-1388 incident.

getOrUndefined() is the safe path: it returns undefined for unknown coins and makes the missing-coin case explicit in the type system. A companion ESLint rule in bgms (local/no-coinmap-raw-get) bans raw .get() calls and enforces this method at dev time.

Test plan

  • yarn workspace @bitgo/statics run unit-test — three new getOrUndefined test cases pass
  • Existing .get() tests unchanged and still passing
  • TypeScript type-check: tsc --noEmit passes with no errors

Ticket: CGD-255

CoinMap.get() throws CoinNotDefinedError for unknown coins, meaning
optional-chaining (?.) provides no protection. Add getOrUndefined()
which returns undefined for unknown coins and delegates to it from
get(), making the missing-coin case explicit in the type system.

Ticket: CGD-255

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Session-Id: 6a81412d-5c4e-462d-959a-3eda803f708c
Task-Id: 562723cc-ae5d-41b5-96c7-d8a533be687c
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Jun 3, 2026

CGD-255

@bitgo-ai-agent-dev bitgo-ai-agent-dev Bot force-pushed the cgd-255-coinmap-get-or-undefined branch from 81309d9 to 366fef5 Compare June 3, 2026 19:44
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.

1 participant