Class TaskNotCancelableError

All Implemented Interfaces:
Serializable, Event

public class TaskNotCancelableError extends A2AProtocolError
A2A Protocol error indicating that a task cannot be canceled in its current state.

This error is returned when a client attempts to cancel a task but the task is in a terminal state (TaskState.TASK_STATE_COMPLETED, TaskState.TASK_STATE_FAILED, TaskState.TASK_STATE_CANCELED) where cancellation is not applicable.

Tasks can only be canceled when they are in non-terminal states such as TaskState.TASK_STATE_SUBMITTED or TaskState.TASK_STATE_WORKING.

Corresponds to A2A-specific error code -32002.

Usage example:


 Task task = taskStore.getTask(taskId);
 if (task.status().state().isFinal()) {
     throw new TaskNotCancelableError(
         "Task in " + task.status().state() + " state cannot be canceled"
     );
 }
 
See Also:
  • Constructor Details

    • TaskNotCancelableError

      public TaskNotCancelableError()
      Constructs error with default message.
    • TaskNotCancelableError

      public TaskNotCancelableError(@Nullable Integer code, @Nullable String message, @Nullable Map<String,Object> details)
      Constructs error with all parameters.
      Parameters:
      code - the error code (defaults to -32002 if null)
      message - the error message (defaults to "Task cannot be canceled" if null)
      details - additional error details (optional)
    • TaskNotCancelableError

      public TaskNotCancelableError(String message)
      Constructs error with custom message.
      Parameters:
      message - the error message