From 129666a9a86690bb72226674d40215f24dc5f7ea Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 17 Nov 2023 10:15:32 +0100 Subject: [PATCH] Wrap cm6-graphql lint logic in try..catch (#3461) * Wrap cm6-graphql lint logic in try..catch * Create silver-lions-build.md --- .changeset/silver-lions-build.md | 5 +++ packages/cm6-graphql/src/lint.ts | 76 +++++++++++++++++--------------- 2 files changed, 45 insertions(+), 36 deletions(-) create mode 100644 .changeset/silver-lions-build.md diff --git a/.changeset/silver-lions-build.md b/.changeset/silver-lions-build.md new file mode 100644 index 00000000000..f33cb60a293 --- /dev/null +++ b/.changeset/silver-lions-build.md @@ -0,0 +1,5 @@ +--- +"cm6-graphql": patch +--- + +Wrap cm6-graphql lint logic in try..catch diff --git a/packages/cm6-graphql/src/lint.ts b/packages/cm6-graphql/src/lint.ts index 69e8513f743..22cc1a06c35 100644 --- a/packages/cm6-graphql/src/lint.ts +++ b/packages/cm6-graphql/src/lint.ts @@ -8,44 +8,48 @@ const SEVERITY = ['error', 'warning', 'info'] as const; export const lint: Extension = linter( view => { - const schema = getSchema(view.state); - if (!schema) { - return []; - } - const results = getDiagnostics(view.state.doc.toString(), schema); + try { + const schema = getSchema(view.state); + if (!schema) { + return []; + } + const results = getDiagnostics(view.state.doc.toString(), schema); - return results - .map((item): Diagnostic | null => { - if (!item.severity || !item.source) { - return null; - } + return results + .map((item): Diagnostic | null => { + if (!item.severity || !item.source) { + return null; + } - const calculatedFrom = posToOffset( - view.state.doc, - new Position(item.range.start.line, item.range.start.character), - ); - const from = Math.max( - 0, - Math.min(calculatedFrom, view.state.doc.length), - ); - const calculatedRo = posToOffset( - view.state.doc, - new Position(item.range.end.line, item.range.end.character - 1), - ); - const to = Math.min( - Math.max(from + 1, calculatedRo), - view.state.doc.length, - ); - return { - from, - to: from === to ? to + 1 : to, - severity: SEVERITY[item.severity - 1], - // source: item.source, // TODO: - message: item.message, - actions: [], // TODO: - }; - }) - .filter((_): _ is Diagnostic => Boolean(_)); + const calculatedFrom = posToOffset( + view.state.doc, + new Position(item.range.start.line, item.range.start.character), + ); + const from = Math.max( + 0, + Math.min(calculatedFrom, view.state.doc.length), + ); + const calculatedRo = posToOffset( + view.state.doc, + new Position(item.range.end.line, item.range.end.character - 1), + ); + const to = Math.min( + Math.max(from + 1, calculatedRo), + view.state.doc.length, + ); + return { + from, + to: from === to ? to + 1 : to, + severity: SEVERITY[item.severity - 1], + // source: item.source, // TODO: + message: item.message, + actions: [], // TODO: + }; + }) + .filter((_): _ is Diagnostic => Boolean(_)); + } catch { + return []; + } }, { needsRefresh(vu) {