Add new errorCode property to notebook errors to see if starting a notebook session failed. (#18617)

This commit is contained in:
Cory Rivera
2022-03-03 14:05:54 -08:00
committed by GitHub
parent 10ff8aa116
commit 0ab4752643
4 changed files with 9 additions and 5 deletions

View File

@@ -108,7 +108,7 @@ export class ExtHostNotebook implements ExtHostNotebookShape {
};
return details;
} catch (error) {
throw typeof (error) === 'string' ? new Error(error) : error;
throw typeof (error) === 'string' ? new Error(error) : Object.assign(error, { errorCode: error.response?.status }); // Add errorCode so that status info persists over RPC
}
});
}

View File

@@ -50,6 +50,8 @@ export class ClientSession implements IClientSession {
private _kernelConfigActions: ((kernelName: string) => Promise<any>)[] = [];
private _connectionId: string = '';
private readonly _kernelNotFoundError = 501;
constructor(private options: IClientSessionOptions) {
this._notebookUri = options.notebookUri;
this._executeManager = options.executeManager;
@@ -62,7 +64,6 @@ export class ClientSession implements IClientSession {
public async initialize(): Promise<void> {
try {
this._serverLoadFinished = this.startServer(this.options.kernelSpec);
await this._serverLoadFinished;
await this.initializeSession();
await this.updateCachedKernelSpec();
} catch (err) {
@@ -116,8 +117,8 @@ export class ClientSession implements IClientSession {
session.defaultKernelLoaded = true;
} catch (err) {
// TODO move registration
if (err && err.response && err.response.status === 501) {
this.options.notificationService.warn(localize('kernelRequiresConnection', "Kernel {0} was not found. The default kernel will be used instead.", kernelSpec.name));
if (err.response?.status === this._kernelNotFoundError || err.errorCode === this._kernelNotFoundError) {
this.options.notificationService.warn(localize('kernelRequiresConnection', "Kernel '{0}' was not found. The default kernel will be used instead.", kernelSpec.name));
session = await this._executeManager.sessionManager.startNew({
path: this.notebookUri.fsPath,
kernelName: undefined