From a679ace42c88ac40d7336f6d8b6266191932a3ea Mon Sep 17 00:00:00 2001 From: Dan Lee <71398022+dandhlee@users.noreply.github.com> Date: Tue, 16 Nov 2021 06:12:31 -0500 Subject: [PATCH] fix: gracefully handle format_code exceptions (#152) --- docfx_yaml/extension.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docfx_yaml/extension.py b/docfx_yaml/extension.py index 38ff86b1..18eb80fc 100644 --- a/docfx_yaml/extension.py +++ b/docfx_yaml/extension.py @@ -28,6 +28,7 @@ from functools import partial from itertools import zip_longest from typing import List +from black import InvalidInput try: from subprocess import getoutput @@ -984,7 +985,11 @@ def format_code(code): def process_signature(app, _type, name, obj, options, signature, return_annotation): if signature: short_name = name.split('.')[-1] - signature = format_code(short_name + signature) + signature = short_name + signature + try: + signature = format_code(signature) + except InvalidInput as e: + print(f"Could not format the given code: \n{e})") app.env.docfx_signature_funcs_methods[name] = signature