diff --git a/packages/core/src/server.ts b/packages/core/src/server.ts index cf0437ec..cd49183b 100644 --- a/packages/core/src/server.ts +++ b/packages/core/src/server.ts @@ -111,10 +111,12 @@ class ThebeServer implements ServerRuntime, ServerRestAPI { ): Promise { await this.ready; - if (!this.sessionManager?.isReady) { + if (!this.sessionManager) { throw Error('Requesting session from a server, with no SessionManager available'); } + await this.sessionManager.ready; + // name is assumed to be a non empty string but is otherwise note required // if a notebook name has been supplied on the path, use that otherwise use a default // https://jupyterlab.readthedocs.io/en/3.4.x/api/modules/services.session.html#isessionoptions @@ -157,12 +159,13 @@ class ThebeServer implements ServerRuntime, ServerRestAPI { async connectToExistingSession(model: SessionIModel, rendermime: IRenderMimeRegistry) { await this.ready; - if (!this.sessionManager?.isReady) { + if (!this.sessionManager) { throw Error('Requesting session from a server, with no SessionManager available'); } - const connection = this.sessionManager?.connectTo({ model }); + await this.sessionManager.ready; + const connection = this.sessionManager?.connectTo({ model }); return new ThebeSession(this, connection, rendermime); } diff --git a/packages/react/src/hooks/notebook.ts b/packages/react/src/hooks/notebook.ts index 8c9f8246..b3045406 100644 --- a/packages/react/src/hooks/notebook.ts +++ b/packages/react/src/hooks/notebook.ts @@ -50,6 +50,7 @@ export function useNotebookBase() { const executeAll = (options?: NotebookExecuteOptions) => { if (!notebook) throw new Error('executeAll called before notebook available'); + if (!session) throw new Error('executeAll called before session available'); options?.before?.(); setExecuting(true); return notebook @@ -69,6 +70,7 @@ export function useNotebookBase() { options?: NotebookExecuteOptions, ) => { if (!notebook) throw new Error('executeSome called before notebook available'); + if (!session) throw new Error('executeAll called before session available'); options?.before?.(); setExecuting(true); const filteredCells = notebook.cells.filter(predicate).map((c) => c.id);