refactor: use toError and NEP-141 storage utils from internal-utils#548
Conversation
WalkthroughThe changes consolidate error handling by replacing local implementations of the Changes
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
src/features/machines/swapIntentMachine.ts (1)
424-431: Guard against missingevent.errorin all onError handlersXState’s invoked service failures populate the error on
event.data(orevent.data.error) rather thanevent.error, so callingerrors.toError(event.error)can end up withError: undefined. Update each occurrence insrc/features/machines/swapIntentMachine.tsto fall back toevent.dataor a literal:Affected locations:
- Line 428
- Line 479
- Line 540
- Line 593
Suggested patch for each handler:
- reason: extractWalletErrorCode(event.error, "ERR_USER_DIDNT_SIGN"), + reason: extractWalletErrorCode(event.error ?? event.data, "ERR_USER_DIDNT_SIGN"), - error: errors.toError(event.error), + error: errors.toError(event.error ?? event.data ?? "Unknown error"),This ensures you never pass
undefinedinto your error converter.
♻️ Duplicate comments (6)
src/features/machines/swapIntentMachine.ts (3)
476-482: Duplicate concern – see previous commentThe same null-safety issue applies here.
537-542: Duplicate concern – see previous commentSame pattern; check the presence of
event.errorbefore callingtoError.
590-595: Duplicate concern – see previous commentSame pattern in the broadcasting error path.
src/utils/errors.ts (1)
35-36: Same semantic verification applies
findErrorrelies on the same guarantee ashasMessage.src/features/machines/signIntentMachine.ts (2)
168-176: Null-safety onevent.error(same issue as swapIntentMachine)Apply the same guard when converting the error payload.
225-229: Null-safety onevent.error(same issue as swapIntentMachine)
🧹 Nitpick comments (3)
src/features/machines/swapIntentMachine.ts (1)
2-2: Import only what you need to keep the bundle slimIf the
@defuse-protocol/internal-utilspackage exportstoErroras a named export, prefer-import { errors } from "@defuse-protocol/internal-utils" +import { toError } from "@defuse-protocol/internal-utils"and call
toError(...)directly.
Bringing in the wholeerrorsnamespace may pull extra helpers into the bundle that are never referenced elsewhere in this module.src/utils/errors.ts (1)
1-1: Rename the imported symbol to avoid cognitive collisionInside
utils/errors.tsimporting an object literally namederrorscan be confusing:import { errors as internalErrors } from "@defuse-protocol/internal-utils"Using an alias keeps a clear distinction between this file’s helpers and the upstream package.
src/features/machines/signIntentMachine.ts (1)
1-1: Alias import for clarity (same as utils/errors.ts)import { errors as internalErrors } from "@defuse-protocol/internal-utils"and update calls accordingly to avoid the double-meaning of “errors” in this domain model.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
src/features/gift/actors/giftMakerRootMachine.ts(2 hunks)src/features/machines/depositMachine.ts(2 hunks)src/features/machines/poaBridgeInfoActor.ts(2 hunks)src/features/machines/signIntentMachine.ts(3 hunks)src/features/machines/swapIntentMachine.ts(5 hunks)src/features/otcDesk/actors/otcMakerRootMachine.ts(2 hunks)src/services/blockchainBalanceService.ts(0 hunks)src/services/nep141StorageService.ts(2 hunks)src/utils/errors.ts(3 hunks)
💤 Files with no reviewable changes (1)
- src/services/blockchainBalanceService.ts
🔇 Additional comments (11)
src/services/nep141StorageService.ts (2)
1-5: LGTM! Clean refactoring to external utilities package.The import changes correctly move NEP-141 storage balance functions from the local blockchain service to the external
@defuse-protocol/internal-utilspackage, and thenearClientimport is properly added to provide the requirednearProviderparameter.
46-46: Correct usage of nearProvider parameter.The
nearProvider: nearClientparameter is properly passed to both function calls, maintaining the same functionality while using the external utility functions.Also applies to: 51-51
src/features/gift/actors/giftMakerRootMachine.ts (2)
1-1: LGTM! Consolidating error utilities to external package.The import correctly changes from local
toErrorutility to the standardizederrorsmodule from@defuse-protocol/internal-utils.
221-221: Correct usage of external toError utility.The function call is properly updated to use
errors.toError(event.error)instead of the localtoError(event.error), maintaining identical functionality while using the external utility.src/features/machines/depositMachine.ts (2)
1-1: LGTM! Consolidating error utilities to external package.The import correctly adds the
errorsmodule from@defuse-protocol/internal-utilsto replace the localtoErrorutility.
214-214: Correct usage of external toError utility.The function call is properly updated to use
errors.toError(event.error)instead of the localtoError(event.error), maintaining identical functionality while using the external utility.src/features/otcDesk/actors/otcMakerRootMachine.ts (2)
1-1: LGTM! Consolidating error utilities to external package.The import correctly changes from local
toErrorutility to the standardizederrorsmodule from@defuse-protocol/internal-utils.
132-132: Correct usage of external toError utility.The function call is properly updated to use
errors.toError(event.error)instead of the localtoError(event.error), maintaining identical functionality while using the external utility.src/features/machines/poaBridgeInfoActor.ts (2)
1-1: LGTM! Consolidating error utilities to external package.The import correctly adds the
errorsmodule from@defuse-protocol/internal-utilsto replace the localtoErrorutility.
94-94: Correct usage of external toError utility.The function call is properly updated to use
errors.toError(event.error)instead of the localtoError(event.error), maintaining identical functionality while using the external utility.src/utils/errors.ts (1)
12-13: Ensure third-partytoErrorpreserves original semanticsThe previous local
toErrorreturned a newErrorwith the original value stringified.
Ifinternal-utilsthrows for non-Error inputs,hasMessagewill throw instead of returningfalse.Verify that:
errors.toError(undefined) // does NOT throwand behaves like the old helper.
* beta: refactor: migrate runtime and waitForIntentSettlement utils (#553) refactor: migrate failover and request utils (#554) refactor: migrate publishIntent(s) function (#552) refactor: migrate logger from internal-utils (#551) refactor: migrate poaBridge utils (#550) refactor: use toError and NEP-141 storage utils from internal-utils (#548)
|
🎉 This PR is included in version 1.0.0-beta.204 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Depends on defuse-protocol/sdk-monorepo#41
Summary by CodeRabbit
Refactor
Chores