Skip to content

Commit

Permalink
refactor: Don't crash on syntax errors and log an error
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Dec 28, 2021
1 parent 7f2c4ec commit 10bb6b1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/griffe/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import asyncio
import sys
import traceback
from contextlib import suppress
from pathlib import Path
from typing import Any, Iterator, Sequence, Tuple
Expand Down Expand Up @@ -211,10 +212,14 @@ def _load_submodule(self, module: Module, subparts: NamePartsType, subpath: Path
member_parent = self._member_parent(module, subparts, subpath)
except UnimportableModuleError as error:
logger.warning(f"{error}. Missing __init__ module?")
else:
return
try:
member_parent[subparts[-1]] = self._load_module_path(
subparts[-1], subpath, submodules=False, parent=member_parent
)
except SyntaxError:
message = traceback.format_exc(limit=0).replace("SyntaxError: invalid syntax", "").strip()
logger.error(f"Syntax error: {message}")


class AsyncGriffeLoader(_BaseGriffeLoader):
Expand Down

0 comments on commit 10bb6b1

Please sign in to comment.