@@ -79,6 +79,10 @@ def append(self, text, underline=None):
7979 super ().append ('' , '' , 1 )
8080
8181
82+ class DependencyError (Exception ):
83+ ...
84+
85+
8286class 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