From 3a318c7b8dc4a84b7b02a275d12df5f0176e0b7a Mon Sep 17 00:00:00 2001 From: William Killerud Date: Fri, 26 Apr 2024 19:17:31 +0200 Subject: [PATCH] fix: wrap scanner's parse in try/catch Don't let an error in one file take down the whole scan --- .../language-server/src/workspace-scanner.ts | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/packages/language-server/src/workspace-scanner.ts b/packages/language-server/src/workspace-scanner.ts index 293175ec..573f9e7c 100644 --- a/packages/language-server/src/workspace-scanner.ts +++ b/packages/language-server/src/workspace-scanner.ts @@ -61,31 +61,35 @@ export default class WorkspaceScanner { return; } - const content = await this.#fs.readFile(uri); + try { + const content = await this.#fs.readFile(uri); - const document = getSCSSRegionsDocument( - TextDocument.create(uri.toString(), "scss", 1, content), - ); - if (!document) return; + const document = getSCSSRegionsDocument( + TextDocument.create(uri.toString(), "scss", 1, content), + ); + if (!document) return; - this.#ls.parseStylesheet(document); + this.#ls.parseStylesheet(document); - const links = await this.#ls.findDocumentLinks(document); - for (const link of links) { - if ( - !link.target || - link.target.endsWith(".css") || - link.target.includes("#{") || - link.target.startsWith("sass:") - ) { - continue; - } + const links = await this.#ls.findDocumentLinks(document); + for (const link of links) { + if ( + !link.target || + link.target.endsWith(".css") || + link.target.includes("#{") || + link.target.startsWith("sass:") + ) { + continue; + } - try { - await this.parse(URI.parse(link.target), depth + 1); - } catch { - // do nothing + try { + await this.parse(URI.parse(link.target), depth + 1); + } catch { + // do nothing + } } + } catch { + // Something went wrong parsing this file, try parsing the others } } }