feat(backend): enhance error recovery for Transaction Signer#1010
Merged
emdevelopa merged 1 commit intoJun 25, 2026
Conversation
|
@Chucks1093 is attempting to deploy a commit to the Emmanuel's projects Team on Vercel. A member of the Team first needs to authorize it. |
…opa#915) Replaces the Transaction Signer's bare catch-and-rethrow pattern with typed, classified errors so callers can branch on failure kind without string-matching. Changes to frontend/src/lib/freighter.ts: - Added TransactionSignerError class with a SignerErrorCode discriminant (WALLET_UNAVAILABLE | USER_REJECTED | INVALID_XDR | NETWORK_MISMATCH | SUBMISSION_FAILED | PUBLIC_KEY_FETCH_FAILED | UNKNOWN) so upstream handlers (usePayment, UI error boundaries) can show context-specific messages instead of a generic fallback - Added classifyFreighterError() which pattern-matches Freighter error messages and maps them to the appropriate code; USER_REJECTED is detected first so wallet UX can prompt a retry without showing an error banner - getFreighterPublicKey() now calls isFreighterAvailable() before attempting the API call, throwing WALLET_UNAVAILABLE immediately if Freighter is not installed or has not granted access, rather than letting the SDK throw an opaque error - signWithFreighter() validates the XDR is non-empty (INVALID_XDR), checks availability (WALLET_UNAVAILABLE), and delegates Freighter errors to classifyFreighterError(); the public-key fetch after signing reuses the hardened getFreighterPublicKey() path - submitTransaction() validates non-empty XDR, wraps fromXDR() in its own try/catch with INVALID_XDR, and re-throws Horizon errors as SUBMISSION_FAILED while passing through any TransactionSignerError that already has a code (avoids double-wrapping) Added frontend/src/lib/freighter.test.ts with 12 vitest cases covering all error codes across all four exported functions. Closes emdevelopa#915 Closes emdevelopa#916 Closes emdevelopa#917 Closes emdevelopa#918
0e50f43 to
79a2a65
Compare
|
@Chucks1093 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #915
Closes #916
Closes #917
Closes #918
What was done
frontend/src/lib/freighter.ts— typed error recovery for the Transaction SignerThe existing implementation swallowed all errors into a single generic string, making it impossible for callers to distinguish a user rejection from a network mismatch or a wallet not being installed. This change introduces structured error recovery across all four exported functions.
TransactionSignerErrorandSignerErrorCodeA new typed error class with a
codediscriminant:WALLET_UNAVAILABLEUSER_REJECTEDINVALID_XDRNETWORK_MISMATCHSUBMISSION_FAILEDPUBLIC_KEY_FETCH_FAILEDgetPublicKey()threw after wallet was confirmed availableUNKNOWNclassifyFreighterError()Internal helper that pattern-matches Freighter error messages and maps them to the correct
SignerErrorCode.USER_REJECTEDis checked first so the UI can offer a retry prompt rather than showing an error banner.getFreighterPublicKey()Now calls
isFreighterAvailable()as a pre-flight check and throwsWALLET_UNAVAILABLEimmediately, rather than letting the Freighter SDK produce an opaque failure.signWithFreighter()transactionXDR→INVALID_XDRbefore any async workWALLET_UNAVAILABLEclassifyFreighterError()getFreighterPublicKey()path for the post-sign public key fetchsubmitTransaction()signedXDR→INVALID_XDRTransactionBuilder.fromXDRin its own try/catch →INVALID_XDRwith the original parse messageTransactionSignerErrorinstances as-is (no double-wrapping)SUBMISSION_FAILEDwith the original message preserved incausefrontend/src/lib/freighter.test.ts(new)12 vitest cases covering every error code path and the success path for all four functions:
isFreighterAvailable— allowed / throwsgetFreighterPublicKey— unavailable, success, fetch failuresignWithFreighter— empty XDR, unavailable, user rejected, successsubmitTransaction— empty XDR, bad parse, success, missing hash