{"record":{"id":"8758777a48f54ca1","repo":"google-gemini/gemini-cli","slug":"a2aclient-canceltask-error-agentname-unexpec","errorCode":null,"errorMessage":"A2AClient cancelTask Error [${agentName}]: Unexpected error: ${String(error)}","messagePattern":"A2AClient cancelTask Error \\[(.+?)\\]: Unexpected error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/agents/a2a-client-manager.ts","lineNumber":288,"sourceCode":"  }\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 });\n      }\n      throw new Error(`${prefix}: Unexpected error: ${String(error)}`);\n    }\n  }\n}\n","sourceCodeStart":270,"sourceCodeEnd":292,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/core/src/agents/a2a-client-manager.ts#L270-L292","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await manager.cancelTask(agentName, taskId);\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e);\n  if (msg.includes('Unexpected error')) {\n    // Non-Error throw from a transport; stringify and report\n    console.error('Non-Error rejection during cancelTask:', msg);\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["a2a","task","error-handling","non-error-throw"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}