{"record":{"id":"e90e14753d4252cb","repo":"neoclide/coc.nvim","slug":"request-cancelled-by-client","errorCode":null,"errorMessage":"Request cancelled by client","messagePattern":"Request cancelled by client","errorType":"exception","errorClass":"LSPCancellationError","httpStatus":null,"severity":"info","filePath":"src/language-client/client.ts","lineNumber":1944,"sourceCode":"  private static RequestsToCancelOnContentModified: Set<string> = new Set([\n    InlayHintRequest.method,\n    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","sourceCodeStart":1926,"sourceCodeEnd":1962,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/language-client/client.ts#L1926-L1962","documentation":"When a server responds with LSP error codes RequestCancelled (-32800) or ServerCancelled (-32802), the client re-raises the cancellation as a CancellationError (or LSPCancellationError carrying server-provided data) instead of returning the default value. This propagates intentional cancellation to the caller's token-based flow.","triggerScenarios":"A sendRequest (e.g. completion, hover) whose server response carries code -32800 or -32802, typically because the client cancelled the request via CancellationToken or the server cancelled it and supplied optional data.","commonSituations":"User keeps typing so stale completion requests are cancelled; server cancels a long-running code-action or rename; the client's cancellation middleware sends $/cancelRequest and the server replies with RequestCancelled.","solutions":["Check the CancellationToken passed to the request and return early when cancellation is requested","Catch CancellationError in the provider and return an empty/default result","Inspect error.data via LSPCancellationError if the server attached cancellation details","Avoid issuing redundant requests (debounce) so they are not cancelled"],"exampleFix":"// before\nconst items = await client.sendRequest(CompletionRequest.type, params, token)\n// after\nlet items\ntry {\n  items = await client.sendRequest(CompletionRequest.type, params, token)\n} catch (e) {\n  if (e instanceof CancellationError || e instanceof LSPCancellationError) return []\n  throw e\n}","handlingStrategy":"try-catch","validationCode":"if (token.isCancellationRequested) return defaultValue","typeGuard":"function isLSPCancellation(e: unknown): e is LSPCancellationError {\n  return e instanceof LSPCancellationError || (e as any)?.code === -32800 || (e as any)?.code === -32802\n}","tryCatchPattern":"try {\n  return await sendRequest(type, params, token)\n} catch (e) {\n  if (isLSPCancellation(e)) return defaultValue\n  throw e\n}","preventionTips":["Debounce rapid requests to reduce server-side cancellation","Always pass and honor the CancellationToken","Return empty results for cancelled requests in feature providers","Log cancellations at debug level, not error level"],"tags":["cancellation","lsp","request"],"backgroundTag":"request-cancelled","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}