diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-10-17 23:44:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-18 00:44:14 +0200 |
commit | 02e5a7a012d0c53a61f5cb38f15b92dd0db4f841 (patch) | |
tree | 126db3d61debbaf6b84972cf75bf233bfa376d97 /cli/tools | |
parent | 50724d014ad6923e228e488648d40ce6f00297e9 (diff) |
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 https://github.com/denoland/deno/issues/26340
Diffstat (limited to 'cli/tools')
-rw-r--r-- | cli/tools/jupyter/server.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/cli/tools/jupyter/server.rs b/cli/tools/jupyter/server.rs index 0cd80f7dd..5680ed4c1 100644 --- a/cli/tools/jupyter/server.rs +++ b/cli/tools/jupyter/server.rs @@ -329,7 +329,12 @@ impl JupyterServer { }) .collect(); - (candidates, cursor_pos - prop_name.len()) + if prop_name.len() > cursor_pos { + // TODO(bartlomieju): most likely not correct, but better than panicking because of sub with overflow + (candidates, cursor_pos) + } else { + (candidates, cursor_pos - prop_name.len()) + } } else { // combine results of declarations and globalThis properties let mut candidates = get_expression_property_names( @@ -349,7 +354,12 @@ impl JupyterServer { candidates.sort(); candidates.dedup(); // make sure to sort first - (candidates, cursor_pos - expr.len()) + if expr.len() > cursor_pos { + // TODO(bartlomieju): most likely not correct, but better than panicking because of sub with overflow + (candidates, cursor_pos) + } else { + (candidates, cursor_pos - expr.len()) + } }; connection |