mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-23 19:59:37 +00:00
extract server error to own file
This commit is contained in:
@@ -18,82 +18,13 @@ import LogDirectoryProvider from '../utils/logDirectoryProvider';
|
|||||||
import Logger from '../utils/logger';
|
import Logger from '../utils/logger';
|
||||||
import { TypeScriptPluginPathsProvider } from '../utils/pluginPathsProvider';
|
import { TypeScriptPluginPathsProvider } from '../utils/pluginPathsProvider';
|
||||||
import { PluginManager } from '../utils/plugins';
|
import { PluginManager } from '../utils/plugins';
|
||||||
import { escapeRegExp } from '../utils/regexp';
|
|
||||||
import TelemetryReporter from '../utils/telemetry';
|
import TelemetryReporter from '../utils/telemetry';
|
||||||
import Tracer from '../utils/tracer';
|
import Tracer from '../utils/tracer';
|
||||||
import { TypeScriptVersion, TypeScriptVersionProvider } from '../utils/versionProvider';
|
import { TypeScriptVersion, TypeScriptVersionProvider } from '../utils/versionProvider';
|
||||||
import { Reader } from '../utils/wireProtocol';
|
import { Reader } from '../utils/wireProtocol';
|
||||||
import { CallbackMap } from './callbackMap';
|
import { CallbackMap } from './callbackMap';
|
||||||
import { RequestItem, RequestQueue, RequestQueueingType } from './requestQueue';
|
import { RequestItem, RequestQueue, RequestQueueingType } from './requestQueue';
|
||||||
|
import { TypeScriptServerError } from './serverError';
|
||||||
class TypeScriptServerError extends Error {
|
|
||||||
|
|
||||||
public static create(
|
|
||||||
version: TypeScriptVersion,
|
|
||||||
response: Proto.Response,
|
|
||||||
): TypeScriptServerError {
|
|
||||||
const parsedResult = TypeScriptServerError.parseErrorText(version, response);
|
|
||||||
return new TypeScriptServerError(version, response,
|
|
||||||
parsedResult ? parsedResult.message : undefined,
|
|
||||||
parsedResult ? parsedResult.stack : undefined);
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
version: TypeScriptVersion,
|
|
||||||
private readonly response: Proto.Response,
|
|
||||||
public readonly serverMessage: string | undefined,
|
|
||||||
public readonly serverStack: string | undefined,
|
|
||||||
) {
|
|
||||||
super(`TypeScript Server Error (${version.versionString})\n${serverMessage}\n${serverStack}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
public get serverErrorText() {
|
|
||||||
return this.response.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get serverCommand() {
|
|
||||||
return this.response.command;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Given a `errorText` from a tsserver request indicating failure in handling a request,
|
|
||||||
* prepares a payload for telemetry-logging.
|
|
||||||
*/
|
|
||||||
private static parseErrorText(
|
|
||||||
version: TypeScriptVersion,
|
|
||||||
response: Proto.Response,
|
|
||||||
) {
|
|
||||||
const errorText = response.message;
|
|
||||||
if (errorText) {
|
|
||||||
const errorPrefix = 'Error processing request. ';
|
|
||||||
if (errorText.startsWith(errorPrefix)) {
|
|
||||||
const prefixFreeErrorText = errorText.substr(errorPrefix.length);
|
|
||||||
const newlineIndex = prefixFreeErrorText.indexOf('\n');
|
|
||||||
if (newlineIndex >= 0) {
|
|
||||||
// Newline expected between message and stack.
|
|
||||||
return {
|
|
||||||
message: prefixFreeErrorText.substring(0, newlineIndex),
|
|
||||||
stack: TypeScriptServerError.normalizeMessageStack(version, prefixFreeErrorText.substring(newlineIndex + 1))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Try to replace full TS Server paths with 'tsserver.js' so that we don't have to post process the data as much
|
|
||||||
*/
|
|
||||||
private static normalizeMessageStack(
|
|
||||||
version: TypeScriptVersion,
|
|
||||||
message: string | undefined,
|
|
||||||
) {
|
|
||||||
if (!message) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return message.replace(new RegExp(`${escapeRegExp(version.path)}[/\\\\]tsserver.js:`, 'gi'), 'tsserver.js:');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TypeScriptServerSpawner {
|
export class TypeScriptServerSpawner {
|
||||||
public constructor(
|
public constructor(
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/*---------------------------------------------------------------------------------------------
|
||||||
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
import * as Proto from '../protocol';
|
||||||
|
import { escapeRegExp } from '../utils/regexp';
|
||||||
|
import { TypeScriptVersion } from '../utils/versionProvider';
|
||||||
|
|
||||||
|
export class TypeScriptServerError extends Error {
|
||||||
|
public static create(
|
||||||
|
version: TypeScriptVersion,
|
||||||
|
response: Proto.Response
|
||||||
|
): TypeScriptServerError {
|
||||||
|
const parsedResult = TypeScriptServerError.parseErrorText(version, response);
|
||||||
|
return new TypeScriptServerError(version, response, parsedResult ? parsedResult.message : undefined, parsedResult ? parsedResult.stack : undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
private constructor(
|
||||||
|
version: TypeScriptVersion,
|
||||||
|
private readonly response: Proto.Response,
|
||||||
|
public readonly serverMessage: string | undefined,
|
||||||
|
public readonly serverStack: string | undefined
|
||||||
|
) {
|
||||||
|
super(`TypeScript Server Error (${version.versionString})\n${serverMessage}\n${serverStack}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get serverErrorText() { return this.response.message; }
|
||||||
|
|
||||||
|
public get serverCommand() { return this.response.command; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a `errorText` from a tsserver request indicating failure in handling a request,
|
||||||
|
* prepares a payload for telemetry-logging.
|
||||||
|
*/
|
||||||
|
private static parseErrorText(version: TypeScriptVersion, response: Proto.Response) {
|
||||||
|
const errorText = response.message;
|
||||||
|
if (errorText) {
|
||||||
|
const errorPrefix = 'Error processing request. ';
|
||||||
|
if (errorText.startsWith(errorPrefix)) {
|
||||||
|
const prefixFreeErrorText = errorText.substr(errorPrefix.length);
|
||||||
|
const newlineIndex = prefixFreeErrorText.indexOf('\n');
|
||||||
|
if (newlineIndex >= 0) {
|
||||||
|
// Newline expected between message and stack.
|
||||||
|
return {
|
||||||
|
message: prefixFreeErrorText.substring(0, newlineIndex),
|
||||||
|
stack: TypeScriptServerError.normalizeMessageStack(version, prefixFreeErrorText.substring(newlineIndex + 1))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to replace full TS Server paths with 'tsserver.js' so that we don't have to post process the data as much
|
||||||
|
*/
|
||||||
|
private static normalizeMessageStack(version: TypeScriptVersion, message: string | undefined) {
|
||||||
|
if (!message) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return message.replace(new RegExp(`${escapeRegExp(version.path)}[/\\\\]tsserver.js:`, 'gi'), 'tsserver.js:');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user