Skip to content

Commit

Permalink
fix: wrap scanner's parse in try/catch
Browse files Browse the repository at this point in the history
Don't let an error in one file take down the whole scan
  • Loading branch information
wkillerud committed Apr 26, 2024
1 parent ab33c6c commit 3a318c7
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions packages/language-server/src/workspace-scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 3a318c7

Please sign in to comment.