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

Show 'Error message' at the top of the stack trace (less scrolling) #8175

Open
Juan-132 opened this issue Apr 5, 2020 · 2 comments
Open

Comments

@Juan-132
Copy link

Juan-132 commented Apr 5, 2020

The most important information to solve an error in your code is arguably the error message (the exception that was raised). This bit of information is printed at the bottom of the stack trace.

When a developer knows the Error message - the most common error's like typo's in variables/functions - or incorrectly called functions/ parameters can be fixed right away.

Current situation
The Error message is printed at the bottom of the stack trace. This works for traditional python development, as the stack trace is printed to the console/output window. Stack traces in a notebook are however viewed from top to bottom.

This is problematic in case of long stack traces (common for errors that originate from packages like pandas/ numpy). To resolve the error, the user will have to scroll down and up multiple pages (to inspect the error messages -- and subsequently fix it in their code).

Suggestion
Include a copy of the Error message at the top of the stack trace.
This way the code containing the error -- and Error message are always visible in the same view.

Mockup
screenshot2

Example error code

import pandas as pd
chipo = pd.read_csv("https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv", sep="\t")
chipo.groupby('item_name').sum()['item_price']
@adamlabadorf
Copy link

Here is a quick workaround you can put at the top of your notebook that will only show the exception and not the full stack:

from functools import partial
f = get_ipython().showtraceback
tb = partial(f,exception_only=True)
get_ipython().showtraceback = tb

or for brevity

from functools import partial
get_ipython().showtraceback = partial(get_ipython().showtraceback,exception_only=True)

@alexZhongvai
Copy link

alexZhongvai commented Jul 10, 2022

Here is a quick workaround you can put at the top of your notebook that will only show the exception and not the full stack:

from functools import partial
f = get_ipython().showtraceback
tb = partial(f,exception_only=True)
get_ipython().showtraceback = tb

or for brevity

from functools import partial
get_ipython().showtraceback = partial(get_ipython().showtraceback,exception_only=True)

Hi, Thanks for this very useful tip. I am new to JupyterLab. Can you kindly recommend how I can run this script for all my notebooks without putting it in every file? Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants