Content-Length: 309267 | pFad | https://github.com/angular/angular/commit/0e9e0348dd972c96ecee8bb990aba8c604dc704f

AA fix(language-service): Update adapter to log instead of throw errors … · angular/angular@0e9e034 · GitHub
Skip to content

Commit 0e9e034

Browse files
atscottthePunderWoman
authored andcommitted
fix(language-service): Update adapter to log instead of throw errors (#60651)
This prevents errors from being thrown from the adapters. Throwing errors in the language service causes the extension to crash. Repeated errors will permanently break the extension. fixes angular/vscode-ng-language-service#2166 PR Close #60651
1 parent 74cd7be commit 0e9e034

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/language-service/src/adapters.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ export class LanguageServiceAdapter implements NgCompilerAdapter {
104104
*/
105105
readResource(fileName: string): string {
106106
if (isTypeScriptFile(fileName)) {
107-
throw new Error(`readResource() should not be called on TS file: ${fileName}`);
107+
console.error(`readResource() should not be called on TS file: ${fileName}`);
108+
return '';
108109
}
109110
// Calling getScriptSnapshot() will actually create a ScriptInfo if it does
110111
// not exist! The same applies for getScriptVersion().
@@ -115,8 +116,9 @@ export class LanguageServiceAdapter implements NgCompilerAdapter {
115116
this.lastReadResourceVersion.set(fileName, version);
116117
const scriptInfo = this.project.getScriptInfo(fileName);
117118
if (!scriptInfo) {
118-
// // This should not happen because it would have failed already at `getScriptVersion`.
119-
throw new Error(`Failed to get script info when trying to read ${fileName}`);
119+
// This should not happen because it would have failed already at `getScriptVersion`.
120+
console.error(`Failed to get script info when trying to read ${fileName}`);
121+
return '';
120122
}
121123
// Add external resources as root files to the project since we project language service
122124
// features for them (this is currently only the case for HTML files, but we could investigate
@@ -155,7 +157,8 @@ export class LSParseConfigHost implements ConfigurationHost {
155157
readFile(path: AbsoluteFsPath): string {
156158
const content = this.serverHost.readFile(path);
157159
if (content === undefined) {
158-
throw new Error(`LanguageServiceFS#readFile called on unavailable file ${path}`);
160+
console.error(`LanguageServiceFS#readFile called on unavailable file ${path}`);
161+
return '';
159162
}
160163
return content;
161164
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/angular/angular/commit/0e9e0348dd972c96ecee8bb990aba8c604dc704f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy