posit-dev / positron

Positron, a next-generation data science IDE
Other
2.51k stars 79 forks source link

Python: Enhance error messages with first stack trace and source links #1175

Closed petetronic closed 9 months ago

petetronic commented 1 year ago

Feedback requested "if we could get trackbacks to automatically display the line of code they originate from (top of the stack) that would save a lot of extra clicking. Then I'd be more okay with having the full traceback hidden by default (as things currently stand if you are in multiple line execution mode in the editor you always need to expand the traceback to find out what line caused the error."

Bonus if we can focus the editor to the source line, if known.

seeM commented 1 year ago

@jjallaire @petetronic Were you thinking of something like this (imagine these had colors as they do in the UI)?

AttributeError: Can't pickle local object 'plot.<locals>.money'

--> 228 plt.show()

Or maybe with the file too, or is that going to be the currently active file 90% of the time?

AttributeError: Can't pickle local object 'plot.<locals>.money'

File ~/posit/bluebook-for-bulldozers/main.py:228
--> 228 plt.show()

Or the whole first stack item?

AttributeError: Can't pickle local object 'plot.<locals>.money'

File ~/posit/bluebook-for-bulldozers/main.py:228
    226 y_lin = x_lin + torch.randn_like(x_lin)
    227 plt.scatter(x_lin, y_lin)
--> 228 plt.show()
    230 xs_lin = x_lin.unsqueeze(1)
    231 x_lin.shape,xs_lin.shape
seeM commented 1 year ago

Here's a neat example of an R dplyr error message:

Screenshot 2023-08-23 at 10 58 29 AM
petetronic commented 1 year ago

Or the whole first stack item?

AttributeError: Can't pickle local object 'plot.<locals>.money'

File ~/posit/bluebook-for-bulldozers/main.py:228
    226 y_lin = x_lin + torch.randn_like(x_lin)
    227 plt.scatter(x_lin, y_lin)
--> 228 plt.show()
    230 xs_lin = x_lin.unsqueeze(1)
    231 x_lin.shape,xs_lin.shape

I like the whole item and if we have file information we should show it. Even better, based on a follow on discussion with JJ, he had also mentioned RStudio navigates the editor to the source of the error too (if known).

seeM commented 1 year ago

@petetronic Agreed, I like the whole item too. I'd also love if Positron navigated to the source. We'd need to do https://github.com/posit-dev/positron/issues/762 first, which would also open the door to https://github.com/posit-dev/positron/issues/761

isabelizimm commented 9 months ago

Confirmed we now have clickable traceback links, which jump to the line in the editor. On version:

Positron Version: 2023.12.0 (Universal) build 1734
Code - OSS Version: 1.85.0
Commit: 2c5283f10482585b1d9df1925d46f7002741633d
Date: 2024-01-03T03:10:14.636Z
Electron: 25.9.7
ElectronBuildId: undefined
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 23.2.0

https://github.com/posit-dev/positron/assets/54685329/c2d290f4-2d55-42a6-8e03-af1390437ffd