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
- Inspect the stringified value in the message to locate which layer threw the non-Error.
- If a custom transport is in use, wrap its internals to always throw Error subclasses.
- Upgrade @a2a-js/sdk and grpc-js to current versions where rejections are normalized.
- 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
- Pin @a2a-js/sdk and grpc-js to versions that normalize rejections to Error.
- Wrap custom transport interceptors so they never throw non-Error values.
- In tests, always reject with Error subclasses.
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
- [A2AClientManager] sendMessageStream Error [${agentName}]: $
- [A2AClientManager] sendMessageStream Error [${agentName}]: U
- A2AClient getTask Error [${agentName}]: ${error.message}
- A2AClient getTask Error [${agentName}]: Unexpected error: ${
- A2AClient cancelTask Error [${agentName}]: ${error.message}
AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12).
Data as JSON: /api/errors/8758777a48f54ca1.
Report an issue: GitHub.