66/* eslint-disable @typescript-eslint/no-explicit-any */
77
88import { commands , Disposable , window } from 'vscode' ;
9+ import * as stackTraceParser from 'stacktrace-parser' ;
910import sendTelemetry from './telemetry' ;
11+ import { ExtenisonID } from './util/constants' ;
1012
1113type VsCommandFunction = ( ...args : any [ ] ) => Promise < any > | any ;
1214
@@ -43,10 +45,20 @@ export async function registerCommands(...modules: string[]): Promise<Disposable
4345 } ;
4446 let result : any ;
4547 const startTime = Date . now ( ) ;
48+ let stackTrace = { } ;
4649 try {
4750 result = await Promise . resolve ( cmd . method . call ( null , ...params ) ) ;
4851 displayResult ( result ) ;
4952 } catch ( err ) {
53+ if ( err . stack ) {
54+ const stack = stackTraceParser . parse ( err . stack ) ;
55+ if ( stack . length > 0 ) {
56+ const files = stack . map ( ( value ) => `${ value . file . substring ( value . file . lastIndexOf ( ExtenisonID ) - 1 ) } :${ value . lineNumber } :${ value . column } ` ) ;
57+ stackTrace = {
58+ 'stack_trace' : files . join ( '\n' )
59+ } ;
60+ }
61+ }
5062 if ( err instanceof VsCommandError ) {
5163 // exception thrown by extension command with meaningful message
5264 // just show it and return
@@ -58,15 +70,15 @@ export async function registerCommands(...modules: string[]): Promise<Disposable
5870 // TODO: Wrap view title commands in try/catch and re-throw as VsCommandError
5971 // TODO: telemetry cannot send not known exception stacktrace or message
6072 // because it can contain user's sensitive information
61- telemetryProps . error = 'Not extension declared exception happened' ;
6273 throw err ;
6374 }
6475 } finally {
6576 telemetryProps . duration = Date . now ( ) - startTime ;
6677 telemetryProps . cancelled = result === null ;
6778 if ( result ?. properties ) {
68- telemetryProps = { ...telemetryProps , ...result . properties } ;
79+ telemetryProps = { ...telemetryProps , ...result . properties } ;
6980 }
81+ telemetryProps = { ...telemetryProps , ...stackTrace } ;
7082 sendTelemetry ( 'command' , telemetryProps ) ;
7183 }
7284 } ) ;
0 commit comments