@@ -13,9 +13,11 @@ import { joinPath } from '../../../../../base/common/resources.js';
1313import { URI } from '../../../../../base/common/uri.js' ;
1414import { localize } from '../../../../../nls.js' ;
1515import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js' ;
16+ import { IDialogService } from '../../../../../platform/dialogs/common/dialogs.js' ;
1617import { IEnvironmentService } from '../../../../../platform/environment/common/environment.js' ;
1718import { FileOperationResult , IFileService , toFileOperationResult } from '../../../../../platform/files/common/files.js' ;
1819import { ILogService } from '../../../../../platform/log/common/log.js' ;
20+ import { IOpenerService } from '../../../../../platform/opener/common/opener.js' ;
1921import { IStorageService , StorageScope , StorageTarget } from '../../../../../platform/storage/common/storage.js' ;
2022import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.js' ;
2123import { IUserDataProfilesService } from '../../../../../platform/userDataProfile/common/userDataProfile.js' ;
@@ -57,6 +59,8 @@ export class ChatSessionStore extends Disposable {
5759 @IUserDataProfilesService private readonly userDataProfilesService : IUserDataProfilesService ,
5860 @IConfigurationService private readonly configurationService : IConfigurationService ,
5961 @IWorkspaceEditingService private readonly workspaceEditingService : IWorkspaceEditingService ,
62+ @IDialogService private readonly dialogService : IDialogService ,
63+ @IOpenerService private readonly openerService : IOpenerService ,
6064 ) {
6165 super ( ) ;
6266
@@ -339,6 +343,8 @@ export class ChatSessionStore extends Disposable {
339343 }
340344 }
341345
346+ private _didReportIssue = false ;
347+
342348 private async writeSession ( session : ChatModel | ISerializableChatData ) : Promise < void > {
343349 try {
344350 const index = this . internalGetIndex ( ) ;
@@ -349,7 +355,32 @@ export class ChatSessionStore extends Disposable {
349355 session . dataSerializer = new ChatSessionOperationLog ( ) ;
350356 }
351357
352- const { op, data } = session . dataSerializer . write ( session ) ;
358+ let op : 'append' | 'replace' ;
359+ let data : VSBuffer ;
360+ try {
361+ ( { op, data } = session . dataSerializer . write ( session ) ) ;
362+ } catch ( e ) {
363+ // This is a big of an ugly prompt, but there is _something_ going on with
364+ // missing sessions. Unfortunately it's hard to root cause because users would
365+ // not notice an error until they reload the window, at which point any error
366+ // is gone. Throw a very verbose dialog here so we can get some quality
367+ // bug reports, if the issue is indeed in the serialized.
368+ // todo@connor 4312: remove after a little bit
369+ if ( ! this . _didReportIssue ) {
370+ this . _didReportIssue = true ;
371+ this . dialogService . prompt ( {
372+ custom : true , // so text is copyable
373+ title : localize ( 'chatSessionStore.serializationError' , 'Error saving chat session' ) ,
374+ message : localize ( 'chatSessionStore.writeError' , 'Error serializing chat session for storage. The session will be lost if the window is closed. Please report this issue to the VS Code team:\n\n{0}' , e . stack || toErrorMessage ( e ) ) ,
375+ buttons : [
376+ { label : localize ( 'reportIssue' , 'Report Issue' ) , run : ( ) => this . openerService . open ( 'https://github.com/microsoft/vscode/issues/new?template=bug_report.md' ) }
377+ ]
378+ } ) ;
379+ }
380+
381+ throw e ;
382+ }
383+
353384 if ( data . byteLength > 0 ) {
354385 await this . fileService . writeFile ( storageLocation . log , data , { append : op === 'append' } ) ;
355386 }
0 commit comments