Skip to content

Commit

Permalink
fix: LSP server crashing in case of error in schema
Browse files Browse the repository at this point in the history
- Added try-catch block around handleWatchedFilesChangedNotification
  handler to prevent server crash on schema update.
  • Loading branch information
A-N-uraag authored and acao committed Nov 20, 2023
1 parent 0c64305 commit 57c2d7f
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,42 +664,47 @@ export class MessageProcessor {
await this._updateFragmentDefinition(uri, contents);
await this._updateObjectTypeDefinition(uri, contents);

const project = this._graphQLCache.getProjectForFile(uri);
if (project) {
await this._updateSchemaIfChanged(project, uri);
}
try {
const project = this._graphQLCache.getProjectForFile(uri);
if (project) {
await this._updateSchemaIfChanged(project, uri);
}

let diagnostics: Diagnostic[] = [];

if (
project?.extensions?.languageService?.enableValidation !== false
) {
diagnostics = (
await Promise.all(
contents.map(async ({ query, range }) => {
const results = await this._languageService.getDiagnostics(
query,
uri,
this._isRelayCompatMode(query),
);
if (results && results.length > 0) {
return processDiagnosticsMessage(results, query, range);
}
return [];
}),
)
).reduce((left, right) => left.concat(right), diagnostics);
}
let diagnostics: Diagnostic[] = [];

if (
project?.extensions?.languageService?.enableValidation !== false
) {
diagnostics = (
await Promise.all(
contents.map(async ({ query, range }) => {
const results = await this._languageService.getDiagnostics(
query,
uri,
this._isRelayCompatMode(query),
);
if (results && results.length > 0) {
return processDiagnosticsMessage(results, query, range);
}
return [];
}),
)
).reduce((left, right) => left.concat(right), diagnostics);
}

this._logger.log(
JSON.stringify({
type: 'usage',
messageType: 'workspace/didChangeWatchedFiles',
projectName: project?.name,
fileName: uri,
}),
);
return { uri, diagnostics };
this._logger.log(
JSON.stringify({
type: 'usage',
messageType: 'workspace/didChangeWatchedFiles',
projectName: project?.name,
fileName: uri,
}),
);
return { uri, diagnostics };
} catch (err) {
this._handleConfigError({ err, uri });
return { uri, diagnostics: [] };
}
}
if (change.type === FileChangeTypeKind.Deleted) {
await this._graphQLCache.updateFragmentDefinitionCache(
Expand Down

0 comments on commit 57c2d7f

Please sign in to comment.