@@ -12,9 +12,11 @@ import { createSingleFileDialog } from '../../../shared/ui/common/openDialog'
1212import {
1313 CodeIterationLimitError ,
1414 ContentLengthError ,
15+ ConversationIdNotFoundError ,
1516 createUserFacingErrorMessage ,
1617 denyListedErrors ,
1718 FeatureDevServiceError ,
19+ IllegalStateTransition ,
1820 MonthlyConversationLimitError ,
1921 NoChangeRequiredException ,
2022 PrepareRepoFailedError ,
@@ -520,7 +522,7 @@ export class FeatureDevController {
520522 await session . sendMetricDataTelemetry (
521523 MetricDataOperationName . EndCodeGeneration ,
522524 result ,
523- 'stack trace: ' + ( err . stack ?? '' )
525+ 'stack trace: ' + this . getStackTraceForError ( err )
524526 )
525527 throw err
526528 } finally {
@@ -1017,4 +1019,54 @@ export class FeatureDevController {
10171019 } )
10181020 }
10191021 }
1022+
1023+ // Should include error messages only for whitelisted exceptions
1024+ // i.e. exceptions with deterministic error messages and do not include sensitive data
1025+ private getStackTraceForError ( error : Error ) : string {
1026+ const seenExceptions = new Set < Error > ( )
1027+ const lines : string [ ] = [ ]
1028+
1029+ function printExceptionDetails ( err : Error , prefix : string = '' ) {
1030+ if ( seenExceptions . has ( err ) ) {
1031+ return
1032+ }
1033+ seenExceptions . add ( err )
1034+
1035+ if (
1036+ err instanceof FeatureDevServiceError ||
1037+ err instanceof ConversationIdNotFoundError ||
1038+ err instanceof TabIdNotFoundError ||
1039+ err instanceof WorkspaceFolderNotFoundError ||
1040+ err instanceof UserMessageNotFoundError ||
1041+ err instanceof SelectedFolderNotInWorkspaceFolderError ||
1042+ err instanceof PromptRefusalException ||
1043+ // err instanceof NoChangeRequiredException ||
1044+ err instanceof PrepareRepoFailedError ||
1045+ err instanceof UploadCodeError ||
1046+ err instanceof UploadURLExpired ||
1047+ err instanceof IllegalStateTransition ||
1048+ err instanceof ContentLengthError ||
1049+ err instanceof ZipFileError ||
1050+ err instanceof CodeIterationLimitError
1051+ ) {
1052+ lines . push ( `${ prefix } ${ err . constructor . name } : ${ err . message } ` )
1053+ } else {
1054+ lines . push ( `${ prefix } ${ err . constructor . name } ` )
1055+ }
1056+
1057+ if ( err . stack ) {
1058+ const callStack = err . stack . substring ( err . stack . indexOf ( err . message ) + err . message . length + 1 )
1059+ lines . push ( `${ prefix } ${ callStack } ` )
1060+ }
1061+
1062+ const cause = ( err as any ) . cause
1063+ if ( cause instanceof Error ) {
1064+ lines . push ( `${ prefix } \tCaused by: ` )
1065+ printExceptionDetails ( cause , `${ prefix } \t` )
1066+ }
1067+ }
1068+
1069+ printExceptionDetails ( error )
1070+ return lines . join ( '\n' )
1071+ }
10201072}
0 commit comments