From 5e9668f9c3f4515f6fe520710164424309eb9ee1 Mon Sep 17 00:00:00 2001 From: Johan Mabille Date: Mon, 12 Apr 2021 10:25:06 +0200 Subject: [PATCH] Catch StopIteration exception in stackFrames --- ipykernel/debugger.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ipykernel/debugger.py b/ipykernel/debugger.py index 5d5116995..db5fbc841 100644 --- a/ipykernel/debugger.py +++ b/ipykernel/debugger.py @@ -315,17 +315,21 @@ async def source(self, message): async def stackTrace(self, message): reply = await self._forward_message(message) - # The stackFrames array has the following content: + # The stackFrames array can have the following content: # { frames from the notebook} # ... # { 'id': xxx, 'name': '', ... } <= this is the first frame of the code from the notebook # { frames from ipykernel } # ... # {'id': yyy, 'name': '', ... } <= this is the first frame of ipykernel code - # We want to remove all the frames from ipykernel - sf_list = reply['body']['stackFrames'] - module_idx = len(sf_list) - next(i for i, v in enumerate(reversed(sf_list), 1) if v['name'] == '' and i != 1) - reply['body']['stackFrames'] = reply['body']['stackFrames'][:module_idx+1] + # or only the frames from the notebook. + # We want to remove all the frames from ipykernel when they are present. + try: + sf_list = reply['body']['stackFrames'] + module_idx = len(sf_list) - next(i for i, v in enumerate(reversed(sf_list), 1) if v['name'] == '' and i != 1) + reply['body']['stackFrames'] = reply['body']['stackFrames'][:module_idx+1] + except StopIteration: + pass return reply def accept_variable(self, variable_name):