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

Prevent committing notebooks with errors in cell outputs #180

Open
janosh opened this issue Dec 24, 2022 · 7 comments
Open

Prevent committing notebooks with errors in cell outputs #180

janosh opened this issue Dec 24, 2022 · 7 comments

Comments

@janosh
Copy link
Contributor

janosh commented Dec 24, 2022

Is it possible to detect whether a cell output is an error + stack trace and let users specify one of 3 options ignore, strip or error? The first would be current behavior of doing nothing, second would remove the cell output and third would exit nbstripout non-zero so that using it as a pre-commit hook aborts commits.

My goal is to prevent accidentally releasing notebooks like this:

Screenshot 2022-12-24 at 13 08 29

@kynan
Copy link
Owner

kynan commented Dec 26, 2022

I would assume errors have some sort of metadata annotation. Do you have an example notebook with an error?

@janosh
Copy link
Contributor Author

janosh commented Dec 26, 2022

Here's one (zipped since GH doesn't allow uploading .ipynb):

index_error.ipynb.zip

[][0]

Screenshot 2022-12-26 at 07 25 05

@janosh
Copy link
Contributor Author

janosh commented Dec 26, 2022

This is the noteobook's relevant JSON:

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "list index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn [1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m [][\u001b[39m0\u001b[39;49m]\n",
      "\u001b[0;31mIndexError\u001b[0m: list index out of range"
     ]
    }
   ],
   "source": [
    "[][0]"
   ]
  }
 ]
}

@janosh
Copy link
Contributor Author

janosh commented Dec 26, 2022

So maybe the trigger could be

any(out["ename"].endswith("Error") for out in outputs)

@kynan
Copy link
Owner

kynan commented Dec 26, 2022

An output_type of error is an indication of error output.

@kynan kynan added this to the Backlog milestone Dec 26, 2022
@kynan
Copy link
Owner

kynan commented Feb 5, 2023

I won't be able to work on implementing this. Contributions welcome!

@kynan
Copy link
Owner

kynan commented Nov 16, 2024

@janosh Are you still interested in this? Would you be happy to work on it?

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

No branches or pull requests

2 participants