Skip to content

Commit a2fc0a2

Browse files
committed
added subprocess failure management
1 parent ce49c92 commit a2fc0a2

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

cylc/sphinx_ext/metadata/__init__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def append(self, text, underline=None):
7979
super().append('', '', 1)
8080

8181

82+
class DependencyError(Exception):
83+
...
84+
85+
8286
class CylcMetadata(SphinxDirective):
8387
"""Represent a Cylc Config.
8488
"""
@@ -125,6 +129,9 @@ def load_global_cfg(conf_path=None):
125129
)
126130
else:
127131
sub = run(['cylc', 'config', '--json'], capture_output=True)
132+
133+
CylcMetadata.check_subproc_output(sub)
134+
128135
return json.loads(sub.stdout)
129136

130137
@staticmethod
@@ -211,6 +218,7 @@ def load_workflow_cfg(conf_path):
211218
['cylc', 'config', '--json', conf_path],
212219
capture_output=True,
213220
)
221+
CylcMetadata.check_subproc_output(sub)
214222
return json.loads(sub.stdout)
215223

216224
@staticmethod
@@ -294,3 +302,22 @@ def write_section(rst, section, title_level='^'):
294302

295303
# Description
296304
rst.append(section.get('description', ''))
305+
306+
@staticmethod
307+
def check_subproc_output(sub):
308+
"""Check subprocess outputs - catch failure.
309+
"""
310+
if sub.returncode:
311+
# Very specifically handle the case where the correct
312+
# version of Cylc isn't installed:
313+
if 'no such option: --json' in sub.stderr.decode():
314+
msg = (
315+
'Requires cylc config --json, not available'
316+
' for this version of Cylc')
317+
raise DependencyError(msg)
318+
# Handle any and all other errors in the subprocess:
319+
else:
320+
msg = 'Cylc config metadata failed with: \n'
321+
msg += '\n'.join(
322+
i.strip("\n") for i in sub.stderr.decode().split('\n'))
323+
raise Exception(msg)

0 commit comments

Comments
 (0)