From 717d05cc2d528deb51cf7785bdd71891935d19a8 Mon Sep 17 00:00:00 2001 From: Armando Aguirre Date: Tue, 7 Jan 2025 15:58:37 -0800 Subject: [PATCH] Fixed BADCLIENT error message (#60925) Co-authored-by: Armando Aguirre Sepulveda --- src/server/session.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/server/session.ts b/src/server/session.ts index 1019a44d85642..120f043e2e83c 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -3058,20 +3058,21 @@ export class Session implements EventSender { codeActions = project.getLanguageService().getCodeFixesAtPosition(file, startPosition, endPosition, args.errorCodes, this.getFormatOptions(file), this.getPreferences(file)); } catch (e) { + const error = e instanceof Error ? e : new Error(e); + const ls = project.getLanguageService(); const existingDiagCodes = [ ...ls.getSyntacticDiagnostics(file), ...ls.getSemanticDiagnostics(file), ...ls.getSuggestionDiagnostics(file), - ].map(d => - decodedTextSpanIntersectsWith(startPosition, endPosition - startPosition, d.start!, d.length!) - && d.code - ); + ] + .filter(d => decodedTextSpanIntersectsWith(startPosition, endPosition - startPosition, d.start!, d.length!)) + .map(d => d.code); const badCode = args.errorCodes.find(c => !existingDiagCodes.includes(c)); if (badCode !== undefined) { - e.message = `BADCLIENT: Bad error code, ${badCode} not found in range ${startPosition}..${endPosition} (found: ${existingDiagCodes.join(", ")}); could have caused this error:\n${e.message}`; + error.message += `\nAdditional information: BADCLIENT: Bad error code, ${badCode} not found in range ${startPosition}..${endPosition} (found: ${existingDiagCodes.join(", ")})`; } - throw e; + throw error; } return simplifiedResult ? codeActions.map(codeAction => this.mapCodeFixAction(codeAction)) : codeActions; }