Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive window not showing stack trace #8568

Closed
thierry-bm opened this issue Dec 16, 2021 · 10 comments · Fixed by #8671
Closed

Interactive window not showing stack trace #8568

thierry-bm opened this issue Dec 16, 2021 · 10 comments · Fixed by #8671
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Milestone

Comments

@thierry-bm
Copy link

thierry-bm commented Dec 16, 2021

Environment data

  • VS Code version: 1.63.1
  • Jupyter Extension version (available under the Extensions sidebar): 2021.11
  • Python Extension version (available under the Extensions sidebar): 2021.12
  • OS (Windows | Mac | Linux distro) and version: Windows 10
  • Python and/or Anaconda version: 3.9.7
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
  • Jupyter server running: Local | Remote | N/A

Expected behaviour

Upon a crash, the interactive window should show which line from my code is responsible for the crash.

Actual behaviour

image

The information does not show the line where the exception was raised. Howver it does show the stack trace if it's raised from a package. But it does not display the line of my code which prompted the exception.

image
image

@thierry-bm thierry-bm added the bug Issue identified by VS Code Team member as probable bug label Dec 16, 2021
@rchiodo
Copy link
Contributor

rchiodo commented Dec 16, 2021

Thanks for the bug. I had some questions about the issue.

Where are you defining and running f from?

For me, if I define f and run f from a python file, this all works fine.
If I define f from the input box at the bottom of the interactive window it doesn't (this is expected as there's no module)

@rchiodo
Copy link
Contributor

rchiodo commented Dec 16, 2021

I think there's a problem with our stack parsing though.

This is coming out if I run f from a separate cell:

image

@thierry-bm
Copy link
Author

If I define and evaluate f within the same cell then the correct behaviour occurs. It's only when f is defined from a previously evaluated "cell" that the bug happens.

@rchiodo
Copy link
Contributor

rchiodo commented Dec 16, 2021

We should update manualTestFile.py to also include this scenario. Our normal just 'raise Exception' isn't sufficient.

@rchiodo rchiodo added this to the January 2022 milestone Dec 16, 2021
@rchiodo rchiodo self-assigned this Jan 10, 2022
@rchiodo
Copy link
Contributor

rchiodo commented Jan 10, 2022

Root cause of problem:

  1. Before starting a cell we set the IPYKERNEL_CELL_NAME. This is necessary so that when debugging, the next execution will use that as the name of a cell so we can map that name in the debugger to the real file.
  2. The problem with this approach is that the value persists beyond the lifetime of the next cell.
  3. This value indicates the 'file' for a cell and when doing a stacktrace on an error, it gets remapped.
  4. Since this 'file' is set for the next 'IPYKERNEL_CELL_NAME', it ends up being the file found in the stacktrace.

Example of execution:

# Code executed to cell cell file name
os.environ["IPYKERNEL_CELL_NAME"] = "cell_1"
# Code for actual cell 1
def badFunc():
  raise Exception("Something bad happened")
# Code executed to cell cell file name
os.environ["IPYKERNEL_CELL_NAME"] = "cell_2"
# Code for actual cell 2
bad_func()

When bad_func() raises an exception, Jupyter will walk the callstack and it will look like this:

cell_1
cell_2

What code actually corresponds to cell_1? The last code executed when this was the environment variable, or more specifically this code:

# Code executed to cell cell file name
os.environ["IPYKERNEL_CELL_NAME"] = "cell_2"

This is what is messing up stack walking.

This also has the side effect of making stepping into other cells not work.

@jaymegordo
Copy link

#139545 Is same issue

@rchiodo
Copy link
Contributor

rchiodo commented Jan 11, 2022

#139545 Is same issue

@jaymegordo Actually that issue is related to this change here: microsoft/vscode#140351.

The stack trace not showing (this issue here) still repros even when the errorRenderer.js file loads. I believe Matt's change in VS code insiders should fix #139545.

@IanMatthewHuff IanMatthewHuff added verified Verification succeeded verification-found Issue verification failed and removed verified Verification succeeded verification-found Issue verification failed labels Jan 27, 2022
@IanMatthewHuff
Copy link
Member

Sorry for the back and forth on the tags. Didn't have the correct extension version:
image
Looks good now and links work.

@Joshuaclymer
Copy link

I'm still having this issue

@radsimu
Copy link

radsimu commented Jan 30, 2023

me too. IPython 8.4. can't click on stacktrace to jump to files

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants