{"record":{"id":"8461df8981559b48","repo":"neoclide/coc.nvim","slug":"request-cancelled-8461df","errorCode":null,"errorMessage":"Request cancelled","messagePattern":"Request cancelled","errorType":"exception","errorClass":"CancellationError","httpStatus":null,"severity":"info","filePath":"src/language-client/diagnostic.ts","lineNumber":486,"sourceCode":"  private createProvider(): DiagnosticProvider {\n    const provider: DiagnosticProvider = {\n      onDidChangeDiagnostics: this.onDidChangeDiagnosticsEmitter.event,\n      provideDiagnostics: (document, previousResultId, token) => {\n        const middleware = this.client.middleware!\n        const client = this._client\n        const provideDiagnostics: ProvideDiagnosticSignature = (document, previousResultId, token) => {\n          const uri = client.code2ProtocolConverter.asUri(document instanceof URI ? document : URI.parse(document.uri))\n          const params: DocumentDiagnosticParams = {\n            identifier: this.options.identifier,\n            textDocument: { uri },\n            previousResultId\n          }\n          return this.sendRequest(DocumentDiagnosticRequest.type, params, token, { kind: DocumentDiagnosticReportKind.Full, items: [] }).then(async result => {\n            if (this.isDisposed) {\n              return { kind: DocumentDiagnosticReportKind.Full, items: [] }\n            }\n            if (token.isCancellationRequested) {\n              throw new CancellationError()\n            }\n            if (result === undefined || result === null) {\n              return { kind: DocumentDiagnosticReportKind.Full, items: [] }\n            }\n            // make handleDiagnostics middleware works\n            if (middleware.handleDiagnostics && result.kind == DocumentDiagnosticReportKind.Full) {\n              middleware.handleDiagnostics(uri, result.items, (_, diagnostics) => {\n                result.items = diagnostics\n              })\n            }\n            return result\n          })\n        }\n        return middleware.provideDiagnostics\n          ? middleware.provideDiagnostics(document, previousResultId, token, provideDiagnostics)\n          : provideDiagnostics(document, previousResultId, token)\n      }\n    }","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/neoclide/coc.nvim/blob/50e974d9692461a69147d5cab146a8d3e439abe4/src/language-client/diagnostic.ts#L468-L504","documentation":"The diagnostics provider throws CancellationError when the cancellation token was fired while awaiting the DocumentDiagnosticRequest response. This avoids processing a stale diagnostic report for a document/version that is no longer relevant.","triggerScenarios":"provideDiagnostics issued a textDocument/diagnostic request; the token was cancelled (buffer changed, pull-diagnostics re-registered, or client disposed) while the request was in flight; on response the token.isCancellationRequested check throws.","commonSituations":"Rapid buffer switching with pull diagnostics enabled; server slow to answer documentDiagnostic requests; refresh interval firing while a previous pull is pending.","solutions":["Treat CancellationError as expected in diagnostic provider wrappers","Ensure the token source is only cancelled when diagnostics are truly invalidated","Check server responsiveness; slow diagnostic responses increase cancellation windows","Return a cached/stale report when cancellation races are frequent"],"exampleFix":"// before\nconst report = await provideDiagnostics(uri, token)\n// after\nconst report = await provideDiagnostics(uri, token).catch(e => {\n  if (e instanceof CancellationError) return { kind: DocumentDiagnosticReportKind.Full, items: [] }\n  throw e\n})","handlingStrategy":"try-catch","validationCode":"if (token.isCancellationRequested) return { kind: DocumentDiagnosticReportKind.Full, items: [] }","typeGuard":"function isCancellationError(e: unknown): e is CancellationError {\n  return e instanceof CancellationError\n}","tryCatchPattern":"try {\n  return await provideDiagnostics(uri, token)\n} catch (e) {\n  if (isCancellationError(e)) return { kind: DocumentDiagnosticReportKind.Full, items: [] }\n  throw e\n}","preventionTips":["Cancel diagnostic tokens only on real invalidation","Cache previous reports to serve during cancellation races","Ensure the diagnostic server responds promptly","Check isCancellationRequested before post-processing results"],"tags":["cancellation","diagnostics","pull-diagnostics"],"backgroundTag":"request-cancelled","analyzedSha":"50e974d9692461a69147d5cab146a8d3e439abe4","analyzedAt":"2026-08-31T11:17:23.966Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}