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

Include link to the cell with an error, in failure heading #483

Merged
merged 6 commits into from
Apr 23, 2020

Conversation

huonw
Copy link
Contributor

@huonw huonw commented Mar 26, 2020

Papermill currently inserts an error message An Exception was encountered at 'In [NNN]' at the top of a notebook that fails to execute, where NNN is the cell execution count of the failing cell. This patch adjusts the In [NNN] text to be a link to the relevant cell, to make it easy to jump to. This works by inserting another markdown cell immediately before the failing cell, where the markdown cell contains an HTML anchor (specifically, id="papermill-error-cell"). The heading then links to it with a #papermill-error-cell fragment HREF.

This helps reduce the scrolling and searching required for long notebooks where the error cell might be one of dozens, or hidden among long output. For an example of the latter, see https://nbviewer.jupyter.org/gist/huonw/dd13fa49b5876bfea26b69832702d573.

huonw added 3 commits March 26, 2020 11:27
Papermill currently inserts an error message "An Exception was encountered at 'In [NNN]'" at the top
of a notebook that fails to execute, where NNN is the cell execution count of the failing cell. This
patch expands the "In [NNN]" text to be a link to the relevant cell, to make it easy to jump
to. This works by inserting another markdown cell immediately before the failing cell, where the
markdown cell contains an HTML anchor (specifically, `id="papermill-error-cell"`). The heading then
links to it with a `#papermill-error-cell` fragment HREF.

This helps reducing the scrolling and searching required for long notebooks where the error cell
might be one of dozens, or hidden among long output. For an example of the latter, see
<https://nbviewer.jupyter.org/gist/huonw/dd13fa49b5876bfea26b69832702d573>.
@codecov
Copy link

codecov bot commented Mar 30, 2020

Codecov Report

Merging #483 into master will increase coverage by 0.13%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #483      +/-   ##
==========================================
+ Coverage   91.42%   91.55%   +0.13%     
==========================================
  Files          14       14              
  Lines        1224     1243      +19     
==========================================
+ Hits         1119     1138      +19     
  Misses        105      105              

Copy link
Member

@MSeal MSeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a downside to this approach is that it leaves this cell around after you fix issues. If we move forward with this, I think we need to tag the cell and remove cells with that tag at the start of execution. However even this will leave the cell around if someone runs with papermill and fixes the issue in a Notebook UI. They'd have to remember to manually remove the error cell.

Thoughts on this problem from other maintainers? @captainsafia @willingc ?

papermill/execute.py Outdated Show resolved Hide resolved
Co-Authored-By: Matthew Seal <mseal007@gmail.com>
@huonw
Copy link
Contributor Author

huonw commented Mar 31, 2020

Yeah, that concern was why I chose to have the second cell have text in it, rather than just <span id="papermill-error-cell"></span>, so that it would be more obvious and more likely that people remember to remove it. I like the approach of tags and automatically remove them, when re-executed via Papermill. I'll whip up an implementation now 😄

I also looked for a Jupyter-native way of linking to specific cells, but couldn't find one. Maybe I missed it?

@MSeal
Copy link
Member

MSeal commented Mar 31, 2020

There is not a Jupyter-native way to link to cells -- it's been a hot topic for debate which likely needs to have a cell id exposed to notebook in the next major format version bump. See jupyter/nbformat#148

Another option is to inject an html output at the end of the cell before's outputs block with the link info. This would make rerunning the notebook in any interface clear the result. Though this would appear in the prior cell's output section which might be visibly odd.

@huonw
Copy link
Contributor Author

huonw commented Mar 31, 2020

I'll whip up an implementation now

Done.

There is not a Jupyter-native way to link to cells -- it's been a hot topic for debate which likely needs to have a cell id exposed to notebook in the next major format version bump. See jupyter/nbformat#148

Ah, I see.

Another option is to inject an html output at the end of the cell before's outputs block with the link info. This would make rerunning the notebook in any interface clear the result. Though this would appear in the prior cell's output section which might be visibly odd.

Ah, so manually edit the output? I think this won't work well if the cell(s) before the error are markdown cells and so don't have separate output?

@MSeal
Copy link
Member

MSeal commented Mar 31, 2020

Ah, so manually edit the output? I think this won't work well if the cell(s) before the error are markdown cells and so don't have separate output?

Yep that's true :/

papermill/execute.py Outdated Show resolved Hide resolved
@captainsafia
Copy link
Member

This is a tricky one. The ideal implementation would store information in the metadata of the notebook and leave each UI to determine how to display this error to the user. While, IMO, that is the best from a design perspective, it's difficult to accomplish.

For compatibility across different UIS and implementation cost, this seems sensible.

Left a quick nit to update the error message so that users can track where it came from (papermill).

@MSeal
Copy link
Member

MSeal commented Apr 21, 2020

I know this has been sitting for awhile -- I'll set some time to hash our if we want papermill to inject the link cell or not with the wider nteract group and get a decision after our next sync.

@willingc @rgbkrk fyi ☝️

@huonw
Copy link
Contributor Author

huonw commented Apr 22, 2020

Thanks for the update; that would be great if you happen to get to it 👍

For a little more context, I'm excited by this tweak or something equivalent, because it'll put the icing on the cake for how we are checking notebooks on CI and making them conveniently viewable: https://medium.com/stellargraph/better-notebooks-through-ci-automatically-testing-documentation-for-graph-machine-learning-5789e277e597 ("Highlighting errors with Buildkite artifacts and annotations" section in particular).

@rgbkrk
Copy link
Member

rgbkrk commented Apr 23, 2020

I like the injected cell at first glance, even with the tradeoff of having to delete that cell later.

Also... kind of tangentially, I think it's ok for us to make cell IDs and stick them in cell metadata when run via papermill. Maybe the way to unblock the inertia on that effort is to start providing something UIs can work with even if it's not fully planned.

@MSeal
Copy link
Member

MSeal commented Apr 23, 2020

Alright from talking I think we're all in agreement with @rgbkrk 's comment above. Going to merge and snap a patch release for this.

@MSeal MSeal merged commit 33b0d8f into nteract:master Apr 23, 2020
@MSeal
Copy link
Member

MSeal commented Apr 23, 2020

Also for cell IDs... i'm going to make a JEP soon based on https://discourse.jupyter.org/t/annotating-jupyter-notebooks/2079/11

@huonw huonw deleted the error-cell-link branch April 23, 2020 21:31
@huonw
Copy link
Contributor Author

huonw commented Apr 23, 2020

Thanks for merging 👍 Hopefully it doesn't take long for there to be a better way to do this!

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

Successfully merging this pull request may close these issues.

4 participants