google-gemini/gemini-cli · error

A2AClient cancelTask Error [${agentName}]: Unexpected error:

Error message

A2AClient cancelTask Error [${agentName}]: Unexpected error: ${String(error)}

What it means

The fallback branch of cancelTask's catch: the underlying rejection was not an Error instance (e.g. a string, plain object, or null thrown by a misbehaving transport). The message stringifies the thrown value. This is defensive code for non-standard throw sites inside @a2a-js/sdk or a custom transport.

Source

Thrown at packages/core/src/agents/a2a-client-manager.ts:288

  }

  /**
   * Cancels a task on an agent.
   * @param agentName The name of the agent.
   * @param taskId The ID of the task to cancel.
   * @returns The cancellation response.
   */
  async cancelTask(agentName: string, taskId: string): Promise<Task> {
    const client = this.clients.get(agentName);
    if (!client) throw new Error(`Agent '${agentName}' not found.`);
    try {
      return await client.cancelTask({ id: taskId });
    } catch (error: unknown) {
      const prefix = `A2AClient cancelTask Error [${agentName}]`;
      if (error instanceof Error) {
        throw new Error(`${prefix}: ${error.message}`, { cause: error });
      }
      throw new Error(`${prefix}: Unexpected error: ${String(error)}`);
    }
  }
}

View on GitHub (pinned to 5024443c72)

Solutions

  1. Inspect the stringified value in the message to locate which layer threw the non-Error.
  2. If a custom transport is in use, wrap its internals to always throw Error subclasses.
  3. Upgrade @a2a-js/sdk and grpc-js to current versions where rejections are normalized.
  4. File the stringified output against the offending package if it originates upstream.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  return await manager.cancelTask(agentName, taskId);
} catch (e) {
  const msg = e instanceof Error ? e.message : String(e);
  if (msg.includes('Unexpected error')) {
    // Non-Error throw from a transport; stringify and report
    console.error('Non-Error rejection during cancelTask:', msg);
  }
  throw e;
}

Prevention

When it happens

Trigger: A transport factory or interceptor threw a non-Error value; a Promise rejection with a bare string/object propagated through the SDK; an edge case in grpc-js rejecting with a non-Error status object on certain Node versions.

Common situations: Third-party transport plugins that do `throw 'timeout'` style rejections; older grpc-js versions that rejected with plain objects; test doubles that reject with strings.

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/8758777a48f54ca1. Report an issue: GitHub.