{"record":{"id":"bcfc33e72d53d233","repo":"neoclide/coc.nvim","slug":"request-cancelled","errorCode":null,"errorMessage":"Request cancelled","messagePattern":"Request cancelled","errorType":"exception","errorClass":"CancellationError","httpStatus":null,"severity":"info","filePath":"src/language-client/client.ts","lineNumber":1946,"sourceCode":"    SemanticTokensRequest.method,\n    SemanticTokensRangeRequest.method,\n    SemanticTokensDeltaRequest.method\n  ])\n\n  public handleFailedRequest<T, P extends { method: string }>(type: P, token: CancellationToken | undefined, error: any, defaultValue: T, showNotification = true): T {\n    if (token && token.isCancellationRequested) return defaultValue\n    // If we get a request cancel or a content modified don't log anything.\n    if (error instanceof ResponseError) {\n      // The connection got disposed while we were waiting for a response.\n      // Simply return the default value. Is the best we can do.\n      if (error.code === ErrorCodes.PendingResponseRejected || error.code === ErrorCodes.ConnectionInactive) {\n        return defaultValue\n      }\n      if (error.code === LSPErrorCodes.RequestCancelled || error.code === LSPErrorCodes.ServerCancelled) {\n        if (error.data != null) {\n          throw new LSPCancellationError(error.data)\n        } else {\n          throw new CancellationError()\n        }\n      } else if (error.code === LSPErrorCodes.ContentModified) {\n        if (BaseLanguageClient.RequestsToCancelOnContentModified.has(type.method)) {\n          throw new CancellationError()\n        } else {\n          return defaultValue\n        }\n      }\n    }\n    this.error(`Request ${type.method} failed.`, error, showNotification)\n    throw error\n  }\n  /**\n   * @internal\n   */\n\n  // Should be kept\n  public logFailedRequest(type: any, error: any): void {","sourceCodeStart":1928,"sourceCodeEnd":1964,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/language-client/client.ts#L1928-L1964","documentation":"Identical family to the RequestCancelled path: for server responses with code -32800/-32802 and no attached data, the client throws a plain CancellationError. Callers using CancellationToken-based APIs should expect this as normal control flow, not a failure.","triggerScenarios":"sendRequest receives error code -32800 (RequestCancelled) or -32802 (ServerCancelled) with error.data == null, so the generic CancellationError is thrown from handleRequestError.","commonSituations":"CancellationToken fired before the server answered; server-side queue eviction of concurrent requests; feature providers (completion, signature help) racing during fast typing.","solutions":["Handle CancellationError explicitly and return a default/empty result","Re-invoke the request with a fresh token if the result is still needed","Pass a linked CancellationToken so cancellation propagates predictably","Enable request debouncing in the calling feature to reduce cancellations"],"exampleFix":"// before\nconst hover = await sendHover(token)\n// after\nconst hover = await sendHover(token).catch(e => {\n  if (e instanceof CancellationError) return null\n  throw e\n})","handlingStrategy":"try-catch","validationCode":"if (token.isCancellationRequested) return defaultValue","typeGuard":"function isCancellationError(e: unknown): e is CancellationError {\n  return e instanceof CancellationError || (e as any)?.name === 'Canceled'\n}","tryCatchPattern":"try {\n  return await sendRequest(type, params, token)\n} catch (e) {\n  if (isCancellationError(e)) return defaultValue // cancellation is control flow\n  throw e\n}","preventionTips":["Treat CancellationError as expected control flow in providers","Link tokens from UI events to requests explicitly","Debounce input-driven requests","Never surface cancellations as user-visible errors"],"tags":["cancellation","lsp","request"],"backgroundTag":"request-cancelled","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}