Skip to content

feat(core): extract error from failed transaction XDR (#193)#204

Open
cybermax4200 wants to merge 1 commit into
Toolbox-Lab:mainfrom
cybermax4200:feat/extract-error-from-failed-tx-xdr
Open

feat(core): extract error from failed transaction XDR (#193)#204
cybermax4200 wants to merge 1 commit into
Toolbox-Lab:mainfrom
cybermax4200:feat/extract-error-from-failed-tx-xdr

Conversation

@cybermax4200
Copy link
Copy Markdown

Closes #193

Summary

Implements from_transaction_result() — the entry point called by prism decode — which navigates a decoded TransactionResult XDR down to the InvokeHostFunctionResult, extracts the failure variant, and maps it to the correct ErrorCategory + code.

Also adds two new PrismError variants required by the spec and wires classify_error() to prefer XDR-based classification when resultXdr is present.

Changes

  • crates/core/src/error.rs — add NotSorobanTransaction and TransactionSucceeded variants to PrismError
  • crates/core/src/decode/host_error.rs
    • from_transaction_result(): navigates TxFailed → OperationResult → InvokeHostFunctionResult and maps each variant to (ErrorCategory, code, is_contract_error)
    • classify_error(): updated to delegate to from_transaction_result() when resultXdr is available
    • 6 unit tests covering all result variants

Test coverage

Case Expected
Trapped ErrorCategory::Contract
ResourceLimitExceeded ErrorCategory::Budget
EntryArchived ErrorCategory::Storage
IHF::Success Err(TransactionSucceeded)
TxSuccess Err(TransactionSucceeded)
No IHF op Err(NotSorobanTransaction)

- Add from_transaction_result() that navigates TransactionResult →
  TxFailed ops → InvokeHostFunctionResult and maps each failure variant
  to the correct ErrorCategory + code
- Add NotSorobanTransaction and TransactionSucceeded variants to
  PrismError for invalid-input cases
- Wire classify_error() to prefer XDR-based classification via
  from_transaction_result() when resultXdr is present
- Add unit tests covering Trapped, ResourceLimitExceeded, EntryArchived,
  IHF success, TxSuccess, and missing IHF cases
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@cybermax4200 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! 🚀

Learn more about application limits

@Emrys02 Emrys02 self-requested a review May 29, 2026 11:07
Copy link
Copy Markdown
Contributor

@Emrys02 Emrys02 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cybermax4200 Fix conflict in your branch

@Emrys02 Emrys02 self-requested a review May 30, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract the Error from a Failed Transaction's Raw XDR Result

2 participants