feat(statics): add CoinMap.getOrUndefined() safe accessor#8937
Draft
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Draft
feat(statics): add CoinMap.getOrUndefined() safe accessor#8937bitgo-ai-agent-dev[bot] wants to merge 1 commit into
bitgo-ai-agent-dev[bot] wants to merge 1 commit into
Conversation
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
81309d9 to
366fef5
Compare
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.
Summary
CoinMap.getOrUndefined(key)to@bitgo/statics— returnsundefinedfor unknown coins instead of throwingCoinNotDefinedErrorget()to delegate its lookup logic togetOrUndefined(), eliminating code duplicationgetOrUndefined()Context
Part of CGD-255 (CR-1388 action item).
CoinMap.get()throwsCoinNotDefinedErrorfor 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 returnsundefinedfor 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 newgetOrUndefinedtest cases pass.get()tests unchanged and still passingtsc --noEmitpasses with no errorsTicket: CGD-255