Skip to content

Commit d1be72b

Browse files
committed
fix(jupyter): fix panics for overslow subtraction (#26371)
I don't have a reliable reproduction for it, but it makes it painful to use the Jupyter kernel with semi-frequent random panics. The completions don't always work correctly anyway, so I think it's better to just not panic here for the time being. Fixes #26340
1 parent 2c0cc4e commit d1be72b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cli/tools/jupyter/server.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,12 @@ impl JupyterServer {
329329
})
330330
.collect();
331331

332-
(candidates, cursor_pos - prop_name.len())
332+
if prop_name.len() > cursor_pos {
333+
// TODO(bartlomieju): most likely not correct, but better than panicking because of sub with overflow
334+
(candidates, cursor_pos)
335+
} else {
336+
(candidates, cursor_pos - prop_name.len())
337+
}
333338
} else {
334339
// combine results of declarations and globalThis properties
335340
let mut candidates = get_expression_property_names(
@@ -349,7 +354,12 @@ impl JupyterServer {
349354
candidates.sort();
350355
candidates.dedup(); // make sure to sort first
351356

352-
(candidates, cursor_pos - expr.len())
357+
if expr.len() > cursor_pos {
358+
// TODO(bartlomieju): most likely not correct, but better than panicking because of sub with overflow
359+
(candidates, cursor_pos)
360+
} else {
361+
(candidates, cursor_pos - expr.len())
362+
}
353363
};
354364

355365
connection

0 commit comments

Comments
 (0)