report tsserver response error as telemetry (#34860)

This commit is contained in:
Arthur Ozga
2017-09-25 13:33:35 -07:00
committed by Matt Bierner
parent 777fddd4f7
commit c8f5358f36

View File

@@ -656,6 +656,8 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
}).catch((err: any) => {
if (!wasCancelled) {
this.error(`'${command}' request failed with error.`, err);
const properties = this.parseErrorText(err && err.message, command);
this.logTelemetry('languageServiceErrorResponse', properties);
}
throw err;
});
@@ -667,6 +669,30 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
return result;
}
/**
* Given a `errorText` from a tsserver request indicating failure in handling a request,
* prepares a payload for telemetry-logging.
*/
private parseErrorText(errorText: string | undefined, command: string) {
const properties: ObjectMap<string> = Object.create(null);
properties['command'] = command;
if (errorText) {
properties['errorText'] = 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.
properties['message'] = prefixFreeErrorText.substring(0, newlineIndex);
properties['stack'] = prefixFreeErrorText.substring(newlineIndex + 1);
}
}
}
return properties;
}
private sendNextRequests(): void {
while (this.callbacks.pendingResponses === 0 && this.requestQueue.length > 0) {
const item = this.requestQueue.shift();