Custom codes for require_uninitialized_* #123
Merged
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.
Problem
Right now it is very hard to understand what is the actual error without querying logs and then inspecting them. This is especially critical in Intent execution & recovery.
For example: we have a case, where finalization failed. User schedules new intent with commit of same account, but since finalization failed we will get
ProgramError::InvalidAccountOwnererror. The problem here is that there're tons of places in Commit instruction that spit outInvalidAccountOwner. So it could be some other thing that went wrong. So in order to know this for certain we would have to usegetTransactionto then inspect error, which brings overhead of using network + another error handling cases"Invalid owner for account. Label: commit state account; account and owner:"
It would be much easier if we would have special code COMMIT_STATE_INVALID_OWNER = 0xsome_code.
This would allow to figure out what went wrong right away from TransactionError type in validator
Solution
Introduce context-aware error mapping for the require_uninitialize_* account/PDA validation helpers.
Each call site now supplies a small context type (e.g.
CommitStateAccountCtx,CommitRecordCtx) implementing aRequireUninitializedAccountCtxtrait.This trait maps low-level validation failures (
invalid_owner,invalid_seeds,already_initialized,immutable) into specificDlpErrorcodes unique to that account role.As a result:
Every failure in commit and related instructions now produces a precise, deterministic error code (e.g.
CommitStateInvalidAccountOwner) instead of genericProgramErrorvariants.Validators and recovery flows can determine the root cause without fetching logs or decoding transaction messages.
Error surfaces become self-describing, improving debugging, intent execution, and protocol safety.
In the future, this pattern can be extended to other helpers (e.g.
require_initialized_pda) via additional traits likeRequireInitializedCtx.Having multiple small traits keeps each helper’s contract focused on exactly the errors it can emit, avoids unused methods, and lets instructions opt into finer-grained error codes incrementally without bloating a single “god” interface.
Before & After Screenshots
Insert screenshots of example code output
BEFORE:
[insert screenshot here]
AFTER:
[insert screenshot here]
Other changes (e.g. bug fixes, small refactors)
Deploy Notes
Notes regarding deployment of the contained body of work. These should note any
new dependencies, new scripts, etc.
New scripts:
script: script detailsNew dependencies:
dependency: dependency detailsSummary by CodeRabbit
Refactor
Bug Fixes / UX
✏️ Tip: You can customize this high-level summary in your review settings.