Skip to content

Commit b22179c

Browse files
authored
Merge pull request #41 from jluethi/patch-1
Move try except into run_and_combine_outputs function
2 parents 835bd5f + f3eba4b commit b22179c

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

jgo/jgo.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,38 @@ def launch_java(
197197
return subprocess.run((java, '-cp', cp) + jvm_args + (main_class,) + app_args, stdout=stdout, stderr=stderr, **subprocess_run_kwargs)
198198

199199
def run_and_combine_outputs(command, *args):
200-
return subprocess.check_output((command,) + args, stderr=subprocess.STDOUT)
201-
200+
try:
201+
return subprocess.check_output((command,) + args, stderr=subprocess.STDOUT)
202+
except subprocess.CalledProcessError as e:
203+
_logger.error("Error in `%s': %d", ' '.join(e.cmd), e.returncode)
204+
_logger.debug("Exception: %s", e)
205+
_logger.debug("Debug Trace:", exc_info=True)
206+
if e.stdout:
207+
_logger.debug("\tstd out:")
208+
for l in str(e.stdout).split('\\n'):
209+
_logger.debug('\t\t%s', l)
210+
if e.stderr:
211+
_logger.debug("\tstd err:")
212+
for l in str(e.stderr).split('\\n'):
213+
_logger.debug('\t\t%s', l)
214+
# parser.print_help(file=sys.stderr)
215+
sys.exit(e.returncode)
216+
217+
except NoMainClassInManifest as e:
218+
_logger.error(e)
219+
_logger.error("No main class given, and none found.")
220+
# parser.print_help(file=sys.stderr)
221+
sys.exit(1)
222+
223+
except HelpRequested as e:
224+
pass
225+
#parser.parse_known_args(e.argv)
226+
227+
except Exception as e:
228+
_logger.error(e)
229+
traceback.print_tb(e.__traceback__)
230+
parser.print_help(file=sys.stderr)
231+
sys.exit(1)
202232

203233
def find_endpoint(argv, shortcuts={}):
204234
# endpoint is first positional argument
@@ -254,38 +284,8 @@ def jgo_main(argv=sys.argv[1:], stdout=None, stderr=None):
254284

255285
parser = jgo_parser()
256286

257-
try:
258-
completed_process = run(parser, argv=argv, stdout=stdout, stderr=stderr)
259-
completed_process.check_returncode()
260-
except subprocess.CalledProcessError as e:
261-
_logger.error("Error in `%s': %d", ' '.join(e.cmd), e.returncode)
262-
_logger.debug("Exception: %s", e)
263-
_logger.debug("Debug Trace:", exc_info=True)
264-
if e.stdout:
265-
_logger.debug("\tstd out:")
266-
for l in str(e.stdout).split('\\n'):
267-
_logger.debug('\t\t%s', l)
268-
if e.stderr:
269-
_logger.debug("\tstd err:")
270-
for l in str(e.stderr).split('\\n'):
271-
_logger.debug('\t\t%s', l)
272-
parser.print_help(file=sys.stderr)
273-
sys.exit(e.returncode)
274-
275-
except NoMainClassInManifest as e:
276-
_logger.error(e)
277-
_logger.error("No main class given, and none found.")
278-
parser.print_help(file=sys.stderr)
279-
sys.exit(1)
280-
281-
except HelpRequested as e:
282-
parser.parse_known_args(e.argv)
283-
284-
except Exception as e:
285-
_logger.error(e)
286-
traceback.print_tb(e.__traceback__)
287-
parser.print_help(file=sys.stderr)
288-
sys.exit(1)
287+
completed_process = run(parser, argv=argv, stdout=stdout, stderr=stderr)
288+
completed_process.check_returncode()
289289

290290

291291
def jgo_cache_dir_environment_variable():

0 commit comments

Comments
 (0)