getFirstFailedSingleTransactionPlanResult

function getFirstFailedSingleTransactionPlanResult<
    TContext,
    TTransactionMessage,
>(
    transactionPlanResult,
): FailedSingleTransactionPlanResult<TContext, TTransactionMessage>;

Retrieves the first failed transaction plan result from a transaction plan result tree.

This function searches the transaction plan result tree using a depth-first traversal and returns the first single transaction result with a 'failed' status. If no failed result is found, it throws a SolanaError.

Type Parameters

Type ParameterDefault typeDescription
TContext extends TransactionPlanResultContextTransactionPlanResultContextThe type of the context object that may be passed along with results
TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer<string>TransactionMessage & TransactionMessageWithFeePayer<string>The type of the transaction message

Parameters

ParameterTypeDescription
transactionPlanResultTransactionPlanResult<TContext, TTransactionMessage>The transaction plan result tree to search.

Returns

FailedSingleTransactionPlanResult<TContext, TTransactionMessage>

The first failed single transaction plan result.

Throws

Throws a SolanaError with code SOLANA_ERROR__INSTRUCTION_PLANS__FAILED_SINGLE_TRANSACTION_PLAN_RESULT_NOT_FOUND if no failed transaction plan result is found. The error context contains a non-enumerable transactionPlanResult property for recovery purposes.

Example

Retrieving the first failed result from a parallel execution.

const result = parallelTransactionPlanResult([
  successfulSingleTransactionPlanResultFromTransaction(messageA, transactionA),
  failedSingleTransactionPlanResult(messageB, error),
  failedSingleTransactionPlanResult(messageC, anotherError),
]);
 
const firstFailed = getFirstFailedSingleTransactionPlanResult(result);
// Returns the failed result for messageB.

See

On this page