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; return details;
} catch (error) { } 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 _kernelConfigActions: ((kernelName: string) => Promise<any>)[] = [];
private _connectionId: string = ''; private _connectionId: string = '';
private readonly _kernelNotFoundError = 501;
constructor(private options: IClientSessionOptions) { constructor(private options: IClientSessionOptions) {
this._notebookUri = options.notebookUri; this._notebookUri = options.notebookUri;
this._executeManager = options.executeManager; this._executeManager = options.executeManager;
@@ -62,7 +64,6 @@ export class ClientSession implements IClientSession {
public async initialize(): Promise<void> { public async initialize(): Promise<void> {
try { try {
this._serverLoadFinished = this.startServer(this.options.kernelSpec); this._serverLoadFinished = this.startServer(this.options.kernelSpec);
await this._serverLoadFinished;
await this.initializeSession(); await this.initializeSession();
await this.updateCachedKernelSpec(); await this.updateCachedKernelSpec();
} catch (err) { } catch (err) {
@@ -116,8 +117,8 @@ export class ClientSession implements IClientSession {
session.defaultKernelLoaded = true; session.defaultKernelLoaded = true;
} catch (err) { } catch (err) {
// TODO move registration // TODO move registration
if (err && err.response && err.response.status === 501) { 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)); 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({ session = await this._executeManager.sessionManager.startNew({
path: this.notebookUri.fsPath, path: this.notebookUri.fsPath,
kernelName: undefined kernelName: undefined

View File

@@ -104,12 +104,14 @@ export function transformErrorForSerialization(error: any): any;
export function transformErrorForSerialization(error: any): any { export function transformErrorForSerialization(error: any): any {
if (error instanceof Error) { if (error instanceof Error) {
let { name, message } = error; let { name, message } = error;
let errorCode = (<any>error).errorCode; // {{SQL CARBON EDIT}} Add error code to retain more information
const stack: string = (<any>error).stacktrace || (<any>error).stack; const stack: string = (<any>error).stacktrace || (<any>error).stack;
return { return {
$isError: true, $isError: true,
name, name,
message, message,
stack stack,
errorCode
}; };
} }

View File

@@ -445,6 +445,7 @@ export class RPCProtocol extends Disposable implements IRPCProtocol {
err.name = value.name; err.name = value.name;
err.message = value.message; err.message = value.message;
err.stack = value.stack; err.stack = value.stack;
err.errorCode = value.errorCode; // {{SQL CARBON EDIT}} Include custom error code
} else { } else {
err = value; err = value;
} }