Skip to content

Commit 09d52e2

Browse files
committed
#299: stop using throw
1 parent 419ec72 commit 09d52e2

File tree

7 files changed

+32
-17
lines changed

7 files changed

+32
-17
lines changed

docs/Installation.ipynb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
},
99
"outputs": [],
1010
"source": [
11-
"from markdown import markdown\n",
1211
"import sys\n",
13-
"sys.path.insert(0, '..')\n",
12+
"\n",
13+
"from markdown import markdown\n",
14+
"\n",
1415
"from versions import (\n",
1516
" JUPYTER_LSP_VERSION,\n",
1617
" JUPYTERLAB_LSP_VERSION,\n",
1718
" JUPYTERLAB_NEXT_MAJOR_VERSION,\n",
1819
" JUPYTERLAB_VERSION,\n",
19-
" REQUIRED_JUPYTERLAB\n",
20-
")"
20+
" REQUIRED_JUPYTERLAB,\n",
21+
")\n",
22+
"\n",
23+
"sys.path.insert(0, \"..\")"
2124
]
2225
},
2326
{

packages/jupyterlab-lsp/src/adapters/codemirror/features/hover.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export class Hover extends CodeMirrorLSPFeature {
201201
e.message === "Cannot read property 'string' of undefined"
202202
)
203203
) {
204-
throw e;
204+
console.warn(e);
205205
}
206206
}
207207
};

packages/jupyterlab-lsp/src/command_manager.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export class NotebookCommandManager extends ContextCommandManager {
201201
return notebook_adapters.get(notebook.id);
202202
}
203203

204-
context_from_active_document(): ICommandContext {
204+
context_from_active_document(): ICommandContext | null {
205205
if (!this.is_widget_current) {
206206
return null;
207207
}
@@ -213,7 +213,7 @@ export class NotebookCommandManager extends ContextCommandManager {
213213

214214
let virtual_editor = this.current_adapter?.virtual_editor;
215215

216-
if (!virtual_editor) {
216+
if (virtual_editor == null) {
217217
return null;
218218
}
219219

@@ -222,6 +222,11 @@ export class NotebookCommandManager extends ContextCommandManager {
222222
cm_cursor
223223
);
224224

225+
if (root_position == null) {
226+
console.warn('Could not retrieve current context', virtual_editor);
227+
return null;
228+
}
229+
225230
return this.current_adapter?.get_context(root_position);
226231
}
227232
}

packages/jupyterlab-lsp/src/manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export class LanguageServerManager implements ILanguageServerManager {
5353
);
5454

5555
if (!response.ok) {
56-
throw new Error(response.statusText);
56+
console.error('Could not fetch sessions', response);
57+
return;
5758
}
5859

5960
let sessions: SCHEMA.Sessions;

packages/jupyterlab-lsp/src/virtual/editors/notebook.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ export class VirtualEditorForNotebook extends VirtualEditor {
118118
transform_from_notebook_to_root(
119119
cell: Cell,
120120
position: IEditorPosition
121-
): IRootPosition {
121+
): IRootPosition | null {
122122
// TODO: if cell is not known, refresh
123123
let shift = this.cell_to_corresponding_source_line.get(cell);
124-
if (shift === undefined) {
125-
throw Error('Cell not found in cell_line_map');
124+
if (shift == null) {
125+
console.warn('Cell not found in cell_line_map');
126+
return null;
126127
}
127128
return {
128129
...(position as CodeMirror.Position),

packages/lsp-ws-connection/src/server-capability-registration.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface IFlexibleServerCapabilities extends ServerCapabilities {
1111
function registerServerCapability(
1212
serverCapabilities: ServerCapabilities,
1313
registration: Registration
14-
): ServerCapabilities {
14+
): ServerCapabilities | null {
1515
const serverCapabilitiesCopy = JSON.parse(
1616
JSON.stringify(serverCapabilities)
1717
) as IFlexibleServerCapabilities;
@@ -27,7 +27,8 @@ function registerServerCapability(
2727
);
2828
}
2929
} else {
30-
throw new Error('Could not register server capability.');
30+
console.warn('Could not register server capability.', registration);
31+
return null;
3132
}
3233

3334
return serverCapabilitiesCopy;

packages/lsp-ws-connection/src/ws-connection.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,14 @@ export class LspWsConnection extends events.EventEmitter
7979
(params: protocol.RegistrationParams) => {
8080
params.registrations.forEach(
8181
(capabilityRegistration: protocol.Registration) => {
82-
this.serverCapabilities = registerServerCapability(
83-
this.serverCapabilities,
84-
capabilityRegistration
85-
);
82+
try {
83+
this.serverCapabilities = registerServerCapability(
84+
this.serverCapabilities,
85+
capabilityRegistration
86+
);
87+
} catch (err) {
88+
console.error(err);
89+
}
8690
}
8791
);
8892

0 commit comments

Comments
 (0)