Skip to content

Commit 516b641

Browse files
committed
feat: add better logging when a parsing error occurs
1 parent 9d94538 commit 516b641

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

arkdoc/generator/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ def _create_files_list(self, parsers: List[Parser]):
3939

4040
for p in parsers:
4141
functions = []
42-
for doc in p.extract_documentation():
43-
functions.append(documentation_to_specification(doc))
42+
for i, doc in enumerate(p.extract_documentation()):
43+
try:
44+
functions.append(documentation_to_specification(doc))
45+
except Exception as e:
46+
logger.error(f"Error while parsing documentation block no {i + 1} inside {p.filename}")
47+
raise e
4448

4549
base = os.path.splitext(os.path.basename(p.filename))[0]
4650
if base in registered:

arkdoc/generator/utils.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,18 @@ def from_txt(doc: Documentation) -> spec.Function:
115115

116116

117117
def documentation_to_specification(doc: Documentation) -> spec.Function:
118-
if doc.source == Source.ArkScript:
119-
return from_ark(doc)
120-
elif doc.source == Source.Cpp:
121-
return from_cpp(doc)
122-
elif doc.source == Source.Txt:
123-
return from_txt(doc)
124-
else:
125-
raise NotImplementedError
118+
try:
119+
if doc.source == Source.ArkScript:
120+
return from_ark(doc)
121+
elif doc.source == Source.Cpp:
122+
return from_cpp(doc)
123+
elif doc.source == Source.Txt:
124+
return from_txt(doc)
125+
except ValueError as e:
126+
logger.error(f"While parsing file a {doc.source}, got an error")
127+
try:
128+
logger.error(str(doc))
129+
except Exception:
130+
logger.warn("Couldn't print the signature of the function")
131+
raise e
132+
raise NotImplementedError

0 commit comments

Comments
 (0)