From 484c0523cdd529f9e261d61a38616b6745075c7f Mon Sep 17 00:00:00 2001 From: Orta Therox Date: Fri, 18 Feb 2022 20:13:54 +0000 Subject: [PATCH] Improve the document cache miss error message (#2161) --- .changeset/chilly-birds-poke.md | 6 ++++++ .../src/MessageProcessor.ts | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changeset/chilly-birds-poke.md diff --git a/.changeset/chilly-birds-poke.md b/.changeset/chilly-birds-poke.md new file mode 100644 index 00000000000..54376e0175f --- /dev/null +++ b/.changeset/chilly-birds-poke.md @@ -0,0 +1,6 @@ +--- +"graphql-language-service-server": patch +"graphql-language-service": patch +--- + +Do not log errors when a JS/TS file has no embedded graphql tags diff --git a/packages/graphql-language-service-server/src/MessageProcessor.ts b/packages/graphql-language-service-server/src/MessageProcessor.ts index 2af5873bb6d..ccd4b5a7654 100644 --- a/packages/graphql-language-service-server/src/MessageProcessor.ts +++ b/packages/graphql-language-service-server/src/MessageProcessor.ts @@ -485,7 +485,7 @@ export class MessageProcessor { const cachedDocument = this._getCachedDocument(textDocument.uri); if (!cachedDocument) { - throw new Error('A cached document cannot be found.'); + return []; } const found = cachedDocument.contents.find(content => { @@ -537,7 +537,7 @@ export class MessageProcessor { const cachedDocument = this._getCachedDocument(textDocument.uri); if (!cachedDocument) { - throw new Error('A cached document cannot be found.'); + return { contents: [] }; } const found = cachedDocument.contents.find(content => { @@ -749,8 +749,9 @@ export class MessageProcessor { const textDocument = params.textDocument; const cachedDocument = this._getCachedDocument(textDocument.uri); if (!cachedDocument || !cachedDocument.contents[0]) { - throw new Error('A cached document cannot be found.'); + return []; } + return this._languageService.getDocumentSymbols( cachedDocument.contents[0].query, textDocument.uri,