{"record":{"id":"edef107b05e35975","repo":"google-gemini/gemini-cli","slug":"a2aclient-gettask-error-agentname-unexpected","errorCode":null,"errorMessage":"A2AClient getTask Error [${agentName}]: Unexpected error: ${String(error)}","messagePattern":"A2AClient getTask Error \\[(.+?)\\]: Unexpected error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/agents/a2a-client-manager.ts","lineNumber":268,"sourceCode":"  }\n\n  /**\n   * Retrieves a task from an agent.\n   * @param agentName The name of the agent.\n   * @param taskId The ID of the task to retrieve.\n   * @returns The task details.\n   */\n  async getTask(agentName: string, taskId: string): Promise<Task> {\n    const client = this.clients.get(agentName);\n    if (!client) throw new Error(`Agent '${agentName}' not found.`);\n    try {\n      return await client.getTask({ id: taskId });\n    } catch (error: unknown) {\n      const prefix = `A2AClient getTask Error [${agentName}]`;\n      if (error instanceof Error) {\n        throw new Error(`${prefix}: ${error.message}`, { cause: error });\n      }\n      throw new Error(`${prefix}: Unexpected error: ${String(error)}`);\n    }\n  }\n\n  /**\n   * Cancels a task on an agent.\n   * @param agentName The name of the agent.\n   * @param taskId The ID of the task to cancel.\n   * @returns The cancellation response.\n   */\n  async cancelTask(agentName: string, taskId: string): Promise<Task> {\n    const client = this.clients.get(agentName);\n    if (!client) throw new Error(`Agent '${agentName}' not found.`);\n    try {\n      return await client.cancelTask({ id: taskId });\n    } catch (error: unknown) {\n      const prefix = `A2AClient cancelTask Error [${agentName}]`;\n      if (error instanceof Error) {\n        throw new Error(`${prefix}: ${error.message}`, { cause: error });","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/core/src/agents/a2a-client-manager.ts#L250-L286","documentation":"Sibling of error 178 from the same getTask catch block, fired when the underlying throw is not an `Error` instance. The manager stringifies it and re-throws a prefixed Error so the operation context is preserved despite the non-standard throw shape.","triggerScenarios":"The A2A client or an injected transport throws a non-Error value (string, number, plain object) from `getTask`. This is the fallback branch when `error instanceof Error` is false.","commonSituations":"A third-party client that throws strings; a fetch shim that rejects with a Response or plain object; an interceptor that strips Error prototypes; legacy code paths that reject with status codes as numbers.","solutions":["Inspect the stringified payload embedded in the message to recover the original signal.","Wrap the A2A client (or fetch) so all rejections become Error instances before reaching getTask.","If you own the client, always throw Error subclasses.","Log the raw caught value alongside the wrapped message for forensic triage."],"exampleFix":"// before — client rejects with a number\nclient.getTask = () => Promise.reject(404);\n\n// after — wrap to Error\nclient.getTask = () => Promise.reject(new Error('404'));\n// or, at the call site:\ntry { await manager.getTask('rev', id); }\ncatch (e) { /* e.message contains 'Unexpected error: 404' */ }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await manager.getTask(name, taskId);\n} catch (e) {\n  // message embeds String(originalError). Log and surface.\n  logger.error({ message: (e as Error).message });\n  // wrap your A2A client so future throws are Error instances.\n}","preventionTips":["Wrap the A2A client so all rejections become Error instances before reaching getTask.","Log the wrapped message verbatim — non-Error causes can't be inspected otherwise.","Audit any transport shim for string/number throws during integration."],"tags":["a2a","tasks","error-handling","robustness"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}