Skip to content

Commit ad6c868

Browse files
authored
string message for known errors (microsoft#259614)
1 parent db9b2fa commit ad6c868

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

src/vs/workbench/api/common/extHostNotebook.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { MarshalledId } from '../../../base/common/marshallingIds.js';
1414
import { isFalsyOrWhitespace } from '../../../base/common/strings.js';
1515
import { assertReturnsDefined } from '../../../base/common/types.js';
1616
import { URI, UriComponents } from '../../../base/common/uri.js';
17+
import { CancellationError } from '../../../base/common/errors.js';
1718
import { IExtensionDescription } from '../../../platform/extensions/common/extensions.js';
1819
import * as files from '../../../platform/files/common/files.js';
1920
import { Cache } from './cache.js';
@@ -318,16 +319,16 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
318319
this.trace(`enter saveNotebook(versionId: ${versionId}, ${uri.toString()})`);
319320

320321
if (!serializer) {
321-
throw new Error('NO serializer found');
322+
throw new NotebookSaveError('NO serializer found');
322323
}
323324

324325
const document = this._documents.get(uri);
325326
if (!document) {
326-
throw new Error('Document NOT found');
327+
throw new NotebookSaveError('Document NOT found');
327328
}
328329

329330
if (document.versionId !== versionId) {
330-
throw new Error('Document version mismatch, expected: ' + versionId + ', actual: ' + document.versionId);
331+
throw new NotebookSaveError('Document version mismatch, expected: ' + versionId + ', actual: ' + document.versionId);
331332
}
332333

333334
if (!this._extHostFileSystem.value.isWritableFileSystem(uri.scheme)) {
@@ -359,11 +360,11 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
359360
await this._validateWriteFile(uri, options);
360361

361362
if (token.isCancellationRequested) {
362-
throw new Error('canceled');
363+
throw new CancellationError();
363364
}
364365
const bytes = await serializer.serializer.serializeNotebook(data, token);
365366
if (token.isCancellationRequested) {
366-
throw new Error('canceled');
367+
throw new CancellationError();
367368
}
368369

369370
// Don't accept any cancellation beyond this point, we need to report the result of the file write
@@ -737,3 +738,10 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
737738
this._logService.trace(`[Extension Host Notebook] ${msg}`);
738739
}
739740
}
741+
742+
export class NotebookSaveError extends Error {
743+
constructor(message: string) {
744+
super(message);
745+
this.name = 'NotebookSaveError';
746+
}
747+
}

src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class NotebookFileWorkingCopyModel extends Disposable implements IStoredF
233233

234234
// Override save behavior to avoid transferring the buffer across the wire 3 times
235235
if (saveWithReducedCommunication) {
236-
this.setSaveDelegate().catch(console.error);
236+
this.setSaveDelegate().catch(error => this._notebookLogService.error('WorkingCopyModel', `Failed to set save delegate: ${error}`));
237237
}
238238
}
239239

@@ -247,7 +247,12 @@ export class NotebookFileWorkingCopyModel extends Disposable implements IStoredF
247247

248248
if (!serializer) {
249249
this._notebookLogService.info('WorkingCopyModel', 'No serializer found for notebook model, checking if provider still needs to be resolved');
250-
serializer = await this.getNotebookSerializer();
250+
serializer = await this.getNotebookSerializer().catch(error => {
251+
this._notebookLogService.error('WorkingCopyModel', `Failed to get notebook serializer: ${error}`);
252+
// The serializer was set initially but somehow is no longer available
253+
this.save = undefined;
254+
throw new NotebookSaveError('Failed to get notebook serializer');
255+
});
251256
}
252257

253258
if (token.isCancellationRequested) {
@@ -257,11 +262,11 @@ export class NotebookFileWorkingCopyModel extends Disposable implements IStoredF
257262
const stat = await serializer.save(this._notebookModel.uri, this._notebookModel.versionId, options, token);
258263
return stat;
259264
} catch (error) {
260-
if (!token.isCancellationRequested) {
265+
if (!token.isCancellationRequested && error.name !== 'Canceled') {
261266
type notebookSaveErrorData = {
262267
isRemote: boolean;
263268
isIPyNbWorkerSerializer: boolean;
264-
error: Error;
269+
error: string;
265270
};
266271
type notebookSaveErrorClassification = {
267272
owner: 'amunger';
@@ -271,10 +276,11 @@ export class NotebookFileWorkingCopyModel extends Disposable implements IStoredF
271276
error: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'Info about the error that occurred' };
272277
};
273278
const isIPynb = this._notebookModel.viewType === 'jupyter-notebook' || this._notebookModel.viewType === 'interactive';
279+
const errorMessage = error.name === 'NotebookSaveError' ? error.message : 'Unknown error';
274280
this._telemetryService.publicLogError2<notebookSaveErrorData, notebookSaveErrorClassification>('notebook/SaveError', {
275281
isRemote: this._notebookModel.uri.scheme === Schemas.vscodeRemote,
276282
isIPyNbWorkerSerializer: isIPynb && this._configurationService.getValue<boolean>('ipynb.experimental.serialization'),
277-
error: error
283+
error: errorMessage
278284
});
279285
}
280286

@@ -313,7 +319,8 @@ export class NotebookFileWorkingCopyModel extends Disposable implements IStoredF
313319
async getNotebookSerializer(): Promise<INotebookSerializer> {
314320
const info = await this._notebookService.withNotebookDataProvider(this.notebookModel.viewType);
315321
if (!(info instanceof SimpleNotebookProviderInfo)) {
316-
throw new Error('CANNOT open file notebook with this provider');
322+
const message = 'CANNOT open notebook with this provider';
323+
throw new NotebookSaveError(message);
317324
}
318325

319326
return info.serializer;
@@ -348,3 +355,10 @@ export class NotebookFileWorkingCopyModelFactory implements IStoredFileWorkingCo
348355
}
349356

350357
//#endregion
358+
359+
class NotebookSaveError extends Error {
360+
constructor(message: string) {
361+
super(message);
362+
this.name = 'NotebookSaveError';
363+
}
364+
}

0 commit comments

Comments
 (0)