33
44import * as path from "path" ;
55import * as vscode from "vscode" ;
6- import { setUserError } from "vscode-extension-telemetry-wrapper" ;
6+ import { sendError , sendInfo , setUserError } from "vscode-extension-telemetry-wrapper" ;
77import { logger , Type } from "./logger" ;
88
99const TROUBLESHOOTING_LINK = "https://github.com/Microsoft/vscode-java-debug/blob/master/Troubleshooting.md" ;
@@ -28,14 +28,10 @@ export class JavaExtensionNotEnabledError extends Error {
2828 }
2929}
3030
31- interface IProperties {
32- [ key : string ] : string ;
33- }
34-
3531interface ILoggingMessage {
36- message : string ;
3732 type ?: Type ;
38- details ?: IProperties ;
33+ message : string ;
34+ stack ?: string ;
3935}
4036
4137interface ITroubleshootingMessage extends ILoggingMessage {
@@ -47,11 +43,22 @@ function logMessage(message: ILoggingMessage): void {
4743 return ;
4844 }
4945
50- if ( message . details ) {
51- logger . log ( message . type , message . details ) ;
46+ if ( message . type === Type . EXCEPTION || message . type === Type . USAGEERROR ) {
47+ const error : Error = {
48+ name : "error" ,
49+ message : message . message ,
50+ stack : message . stack ,
51+ } ;
52+ if ( message . type === Type . USAGEERROR ) {
53+ setUserError ( error ) ;
54+ }
55+ sendError ( error ) ;
5256 } else {
53- logger . logMessage ( message . type , message . message ) ;
57+ sendInfo ( null , { message : message . message } ) ;
5458 }
59+
60+ // Deprecated
61+ logger . log ( message . type , { message : message . message , stack : message . stack } ) ;
5562}
5663
5764export async function showInformationMessage ( message : ILoggingMessage , ...items : string [ ] ) : Promise < string | undefined > {
@@ -95,6 +102,12 @@ function handleTroubleshooting(choice: string, message: string, anchor: string):
95102
96103export function openTroubleshootingPage ( message : string , anchor : string ) {
97104 vscode . commands . executeCommand ( "vscode.open" , vscode . Uri . parse ( anchor ? `${ TROUBLESHOOTING_LINK } #${ anchor } ` : TROUBLESHOOTING_LINK ) ) ;
105+ sendInfo ( null , {
106+ troubleshooting : "yes" ,
107+ troubleshootingMessage : message ,
108+ } ) ;
109+
110+ // Deprecated
98111 logger . log ( Type . USAGEDATA , {
99112 troubleshooting : "yes" ,
100113 troubleshootingMessage : message ,
@@ -122,7 +135,16 @@ async function installJavaExtension() {
122135 }
123136}
124137
125- export function formatErrorProperties ( ex : any ) : IProperties {
138+ export function convertErrorToMessage ( err : Error ) : ILoggingMessage {
139+ const properties = formatErrorProperties ( err ) ;
140+ return {
141+ type : Type . EXCEPTION ,
142+ message : properties . message ,
143+ stack : properties . stackTrace ,
144+ } ;
145+ }
146+
147+ function formatErrorProperties ( ex : any ) : any {
126148 const exception = ( ex && ex . data && ex . data . cause )
127149 || { stackTrace : ( ex && ex . stack ) , detailMessage : String ( ( ex && ex . message ) || ex || "Unknown exception" ) } ;
128150
0 commit comments