passthroughFailedTransactionPlanExecution

Call Signature

function passthroughFailedTransactionPlanExecution<TContext>(
    promise,
): Promise<SingleTransactionPlanResult<TContext>>;

Wraps a transaction plan execution promise to return a TransactionPlanResult even on execution failure.

When a transaction plan executor throws a SOLANA_ERROR__INSTRUCTION_PLANS__FAILED_TO_EXECUTE_TRANSACTION_PLAN error, this helper catches it and returns the TransactionPlanResult from the error context instead of throwing.

This allows us to handle the result of an execution in a single unified way instead of using try/catch and examine the TransactionPlanResult in both success and failure cases.

Any other errors are re-thrown as normal.

Type Parameters

Type ParameterDefault typeDescription
TContext extends TransactionPlanResultContextTransactionPlanResultContextWithSignatureThe type of the context object attached to the results. Any context is accepted, since this helper never reads from it.

Parameters

ParameterTypeDescription
promisePromise<SingleTransactionPlanResult<TContext>>A promise returned by a transaction plan executor.

Returns

Promise<SingleTransactionPlanResult<TContext>>

A promise that resolves to the transaction plan result, even if some transactions failed.

Example

Handling failures using a single result object:

const result = await passthroughFailedTransactionPlanExecution(
  transactionPlanExecutor(transactionPlan)
);
 
const summary = summarizeTransactionPlanResult(result);
if (summary.successful) {
  console.log('All transactions executed successfully');
} else {
  console.log(`${summary.successfulTransactions.length} succeeded`);
  console.log(`${summary.failedTransactions.length} failed`);
  console.log(`${summary.canceledTransactions.length} canceled`);
}

See

Call Signature

function passthroughFailedTransactionPlanExecution<TContext>(
    promise,
): Promise<TransactionPlanResult<TContext>>;

Wraps a transaction plan execution promise to return a TransactionPlanResult even on execution failure.

When a transaction plan executor throws a SOLANA_ERROR__INSTRUCTION_PLANS__FAILED_TO_EXECUTE_TRANSACTION_PLAN error, this helper catches it and returns the TransactionPlanResult from the error context instead of throwing.

This allows us to handle the result of an execution in a single unified way instead of using try/catch and examine the TransactionPlanResult in both success and failure cases.

Any other errors are re-thrown as normal.

Type Parameters

Type ParameterDefault typeDescription
TContext extends TransactionPlanResultContextTransactionPlanResultContextWithSignatureThe type of the context object attached to the results. Any context is accepted, since this helper never reads from it.

Parameters

ParameterTypeDescription
promisePromise<TransactionPlanResult<TContext>>A promise returned by a transaction plan executor.

Returns

Promise<TransactionPlanResult<TContext>>

A promise that resolves to the transaction plan result, even if some transactions failed.

Example

Handling failures using a single result object:

const result = await passthroughFailedTransactionPlanExecution(
  transactionPlanExecutor(transactionPlan)
);
 
const summary = summarizeTransactionPlanResult(result);
if (summary.successful) {
  console.log('All transactions executed successfully');
} else {
  console.log(`${summary.successfulTransactions.length} succeeded`);
  console.log(`${summary.failedTransactions.length} failed`);
  console.log(`${summary.canceledTransactions.length} canceled`);
}

See

On this page