Skip to content

Commit 3c9a575

Browse files
committed
Make errors coming from Crystal clearer
1 parent d1b6fee commit 3c9a575

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

mkdocstrings/handlers/crystal/collector.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66
import subprocess
77
from typing import Any, Callable, Iterable, Iterator, Mapping, Sequence, TypeVar, Union
88

9+
import mkdocs.exceptions
910
import mkdocs.utils
1011
from cached_property import cached_property
1112
from mkdocstrings.handlers.base import BaseCollector, CollectionError
1213

1314
from .items import DocConstant, DocItem, DocMapping, DocMethod, DocModule, DocType
1415

16+
try:
17+
from mkdocs.exceptions import PluginError
18+
except ImportError:
19+
PluginError = SystemExit
20+
1521
log = logging.getLogger(f"mkdocs.plugins.{__name__}")
1622
log.addFilter(mkdocs.utils.warning_filter)
1723

@@ -47,11 +53,19 @@ def __init__(self, crystal_docs_flags: Sequence[str] = ()):
4753
self._proc = subprocess.Popen(command, stdout=subprocess.PIPE)
4854
self._collected = collections.Counter()
4955

56+
# pytype: disable=bad-return-type
5057
@cached_property
5158
def root(self) -> DocModule:
5259
"""The top-level namespace, represented as a fake module."""
53-
with self._proc:
54-
return DocModule(json.load(self._proc.stdout)["program"], None, None)
60+
try:
61+
with self._proc:
62+
return DocModule(json.load(self._proc.stdout)["program"], None, None)
63+
finally:
64+
if self._proc.returncode:
65+
cmd = " ".join(shlex.quote(arg) for arg in self._proc.args)
66+
raise PluginError(f"Command `{cmd}` exited with status {self._proc.returncode}")
67+
68+
# pytype: enable=bad-return-type
5569

5670
def collect(self, identifier: str, config: Mapping[str, Any]) -> "DocView":
5771
"""[Find][mkdocstrings.handlers.crystal.items.DocItem.lookup] an item by its identifier.

0 commit comments

Comments
 (0)