Skip to content

Commit

Permalink
Make Jinja2 errors and OSErrors produce a clearer message (#2801)
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Mar 26, 2022
1 parent 052ba86 commit bd456e7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mkdocs/commands/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from urllib.parse import urlsplit
from os.path import isdir, isfile, join

import jinja2.exceptions

from mkdocs.commands.build import build
from mkdocs.config import load_config
from mkdocs.exceptions import Abort
Expand Down Expand Up @@ -93,9 +95,12 @@ def error_handler(code):
log.info("Shutting down...")
finally:
server.shutdown()
except jinja2.exceptions.TemplateError:
# This is a subclass of OSError, but shouldn't be suppressed.
raise
except OSError as e: # pragma: no cover
# Avoid ugly, unhelpful traceback
raise Abort(str(e))
raise Abort(f'{type(e).__name__}: {e}')
finally:
if isdir(site_dir):
shutil.rmtree(site_dir)

0 comments on commit bd456e7

Please sign in to comment.