Skip to content

Errors in preview cause django traceback #16

@drnlm

Description

@drnlm

As seen in the za.pycon.org error logs:

File "<ve>/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "<ve>/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "<ve>/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "<ve>/site-packages/markitup/views.py" in apply_filter
  10.     markup = filter_func(request.POST.get('data', ''))

File "<ve>/site-packages/markdown/core.py" in markdown
  387.     return md.convert(text)

File "<ve>/site-packages/markdown/core.py" in convert
  261.             self.lines = prep.run(self.lines)

File "<ve>/site-packages/markdown/preprocessors.py" in run
  81.         parser.close()

File "<ve>/site-packages/markdown/htmlparser.py" in close
  78.         super().close()

File "/usr/lib/python3.8/html/parser.py" in close
  115.         self.goahead(1)

File "/usr/lib/python3.8/html/parser.py" in goahead
  173.                     k = self.parse_endtag(i)

File "/usr/lib/python3.8/html/parser.py" in parse_endtag
  421.         self.handle_endtag(elem)

File "<ve>/site-packages/markdown/htmlparser.py" in handle_endtag
  148.         text = self.get_endtag_text(tag)

File "<ve>/site-packages/markdown/htmlparser.py" in get_endtag_text
  118.         start = self.line_offset + self.offset

File "<ve>/site-packages/markdown/htmlparser.py" in line_offset
  95.             return re.match(r'([^\n]*\n){{{}}}'.format(self.lineno-1), self.rawdata).end()

Exception Type: AttributeError at /markitup/preview/
Exception Value: 'NoneType' object has no attribute 'end'

While we can't do much about malformed input, we really should handle errors during preview better, and provide some other form of feedback if this happens, and only span the logs if invalid input is actually submitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions