Add signing error codes and factories - #1902
Conversation
🦋 Changeset detectedLatest commit: 38a12b2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 48 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
5f43f7b to
5305a0c
Compare
e85b097 to
ebdc059
Compare
BundleMonFiles updated (6)
Unchanged files (144)
Total files change +199B +0.03% Final result: ✅ View report in BundleMon website ➡️ |
BundleMonFiles updated (13)
Unchanged files (137)
Total files change +1.73KB +0.31% Final result: ✅ View report in BundleMon website ➡️ |
trevor-cortex
left a comment
There was a problem hiding this comment.
Summary
Adds SOLANA_ERROR__FAILED_TO_SIGN_TRANSACTION[S] error codes (13/14) to @solana/errors and their createFailedToSignTransaction[s]Error factories in @solana/instruction-plans, mirroring the existing failed-to-send codes. The implementation is a clean refactor: the bodies of the two send factories are extracted into shared getSingleFailureContext / getMultipleFailuresContext helpers, parameterized by an includeSubmissionIndicator flag that the sign variants set to false so the message drops the (preflight) / signature prefix while keeping logs and preflightData intact.
What I checked
- Behavior preservation for send: the extracted helpers are line-for-line equivalent to the previous inlined logic when
includeSubmissionIndicatoristrue— no behavioral change to the send factories. - Registry consistency: codes 13/14 are appended sequentially in the correct range, and the
context.ts/messages.ts/SolanaErrorCodeunion entries are all present and alphabetically ordered. Context shapes exactly mirror the send counterparts, including the non-enumerabletransactionPlanResult. - Message formatting: with an empty indicator, the single message becomes
Failed to sign transaction: <cause>and plural lines become[Tx #1] <cause>— both covered by tests, including the edge case where a stray signature exists in the result context and is correctly omitted. - Tests: thorough coverage of preflight unwrapping, cause propagation (single vs. multiple failures), cancellation with/without abort reason, non-enumerable
transactionPlanResult, and error codes — matching the structure of the existing send tests. - Changeset: present,
minorfor both packages, which fits an additive error-code + factory feature.
Notes for other reviewers
- The
true /* includeSubmissionIndicator *//false /* ... */call-site comments make the boolean flag readable enough that I don't think an options object is warranted for an internal helper. createFailedToSignTransactionsErrorreusesTransactionPlanResultWithOptionalSignatureas its parameter type even though sign flows never produce signatures. That's the pragmatic choice since the plumbing is shared with send; a narrower type would add surface area for no real safety gain, so I wouldn't push on it.- The helpers return
Record<string, unknown>and rely on theSolanaErrorconstructor accepting it, same as the pre-existing inlined code — no change in type rigor there.
LGTM — would approve, but I don't have approval permissions on this repo, so submitting as a comment instead.
|
Documentation Preview: https://kit-docs-17x6mtvxu-anza-tech.vercel.app |
5305a0c to
b322240
Compare
ebdc059 to
b2f9a3c
Compare
Pull request was converted to draft
b322240 to
70ac031
Compare
567e5e7 to
d5ce66b
Compare
70ac031 to
c207d3b
Compare
Signing a transaction can fail in most of the ways sending can — a signer refuses, a required signer is missing, or the simulation used to estimate resource limits fails — but Kit only had error codes for send failures, so a client capability that signs without submitting had nothing accurate to throw. This adds `SOLANA_ERROR__FAILED_TO_SIGN_TRANSACTION` and `SOLANA_ERROR__FAILED_TO_SIGN_TRANSACTIONS` along with the `createFailedToSignTransactionError` and `createFailedToSignTransactionsError` factories that raise them, so a signing wrapper can translate the low-level `SOLANA_ERROR__INSTRUCTION_PLANS__FAILED_TO_EXECUTE_TRANSACTION_PLAN` thrown by an executor into a user-facing error the same way the sending wrappers already do. The context shapes are deliberately identical to their send counterparts, including the non-enumerable `transactionPlanResult` and the optional `logs` and `preflightData`. Those simulation fields are not vestigial for signing: resource-limit estimation runs inside `executeTransactionMessage` before the signing step, so an estimation failure lands on a failed leaf and reaches the error exactly as it does when sending. Keeping the shapes identical also lets one extracted context builder serve both pairs of factories and keeps the two codes interchangeable at the catch site. Where the signing errors differ is the message, which carries no indicator of where the failure happened. That indicator locates a failure relative to network submission — `(preflight)` before it, or the transaction signature after it — and signing never submits, so neither branch has anything to say. A signature would actively mislead, implying the transaction reached the network when it never did. Only the prefix is dropped: `logs` and `preflightData` remain on the context, and the log snippet still appears in the message, so a simulation failure is still legible. Extracting the shared context builders leaves the send factories behaviorally unchanged and every pre-existing send test unmodified, which is what guards the refactor.
d5ce66b to
e9ff80a
Compare
c207d3b to
38a12b2
Compare

Summary of Changes
This PR adds Kit error codes for a
signTransactionplugin to use:SOLANA_ERROR__FAILED_TO_SIGN_TRANSACTION[s]These have the same shaped context as sign, because while
signTransactionis not expected to actually send a transaction to the network, it may for example simulate to estimate CUs. In this caselogsandpreflightDataare useful context for a failed simulation during signing.We also add helpers
createFailedToSignTransactionError[s], again mirroring how the equivalent send helpers construct these errors. The only difference is that we skip the call togetFailedIndicatorwhich attaches a preflight indicator or a signature, neither of which are useful for the sign error message.The logic to implement these is shared with the send helpers.