Skip to content

Commit

Permalink
Add an invalid notebook error (#1675)
Browse files Browse the repository at this point in the history
* Add an invalid notebook error
Motivation:
  - As we are now service hundreds of thousands of notebooks a day, we are
    seeing a number of errors from Notebook rendering that really stem
    from notebooks not being properly formated. These show up in a number
    of errors such as the error handled in this pr, an assertion error,
    we have also seen key errors and others. This pr is a bit of a proposal
    to instead introduced a common exception that indicates the notebook
    is missing some required data that is needed to render itself.

* Update nbconvert/filters/markdown_mistune.py

Co-authored-by: Matthias Bussonnier <bussonniermatthias@gmail.com>

Co-authored-by: Matthias Bussonnier <bussonniermatthias@gmail.com>
  • Loading branch information
gwincr11 and Carreau committed Dec 10, 2021
1 parent b9addb2 commit 88ee3d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nbconvert/filters/markdown_mistune.py
Expand Up @@ -160,7 +160,10 @@ def image(self, src, title, text):
attachment_prefix = 'attachment:'
if src.startswith(attachment_prefix):
name = src[len(attachment_prefix):]
assert name in attachments, "missing attachment: {}".format(name)

if not name in attachments:
raise InvalidNotebook("missing attachment: {}".format(name))

attachment = attachments[name]
# we choose vector over raster, and lossless over lossy
preferred_mime_types = ['image/svg+xml', 'image/png', 'image/jpeg']
Expand Down
3 changes: 3 additions & 0 deletions nbconvert/nbconvertapp.py
Expand Up @@ -595,6 +595,9 @@ def initialize(self, argv=None):
def default_export_format(self):
return 'html'

class InvalidNotebook(Exception):
pass

#-----------------------------------------------------------------------------
# Main entry point
#-----------------------------------------------------------------------------
Expand Down

0 comments on commit 88ee3d3

Please sign in to comment.