Browse Source

main.py, exec_wrapper.py: improve error output

The MMGen Project 8 months ago
parent
commit
79f1bac97f
4 changed files with 14 additions and 12 deletions
  1. 3 4
      mmgen/main.py
  2. 9 5
      scripts/exec_wrapper.py
  3. 0 1
      test/cmdtest_py_d/ct_misc.py
  4. 2 2
      test/tooltest2.py

+ 3 - 4
mmgen/main.py

@@ -41,10 +41,6 @@ def launch(*, mod=None, func=None, package='mmgen'):
 		sys.stderr.write(yellow('\nEnd of file\n'))
 		sys.exit(1)
 	except Exception as e:
-
-		if os.getenv('MMGEN_EXEC_WRAPPER'):
-			raise
-
 		try:
 			errmsg = str(e.args[0])
 		except:
@@ -70,6 +66,9 @@ def launch(*, mod=None, func=None, package='mmgen'):
 				e = e))
 			+ '\n' )
 
+		if os.getenv('MMGEN_EXEC_WRAPPER'):
+			raise
+
 		sys.exit(d.exit_val)
 
 	except SystemExit as e:

+ 9 - 5
scripts/exec_wrapper.py

@@ -38,7 +38,7 @@ def exec_wrapper_write_traceback(e,exit_val):
 	import sys,os
 
 	exc_line = (
-		repr(e) if type(e).__name__ in ('MMGenError','MMGenSystemExit') else
+		f'{type(e).__name__}({e.mmcode})' if type(e).__name__ in ('MMGenError','MMGenSystemExit') else
 		f'{type(e).__name__}: {e}')
 
 	c = exec_wrapper_get_colors()
@@ -68,14 +68,18 @@ def exec_wrapper_write_traceback(e,exit_val):
 		if 'SystemExit' in exc_line:
 			tb_lines.pop()
 
-		sys.stdout.write('{}\n{}\n'.format( c.yellow( '\n'.join(tb_lines) ), c.red(exc_line) ))
+		if os.getenv('EXEC_WRAPPER_EXIT_OK'):
+			sys.stdout.write(c.red(exc_line))
+		else:
+			sys.stdout.write('{}\n{}\n'.format(
+				c.yellow('\n'.join(tb_lines)),
+				c.red(exc_line)))
+			print(c.blue('{} script exited with error').format(
+				'Test' if os.path.dirname(sys.argv[0]) == 'test' else 'Spawned' ))
 
 		with open('test.err','w') as fp:
 			fp.write('\n'.join(tb_lines + [exc_line]))
 
-		print(c.blue('{} script exited with error').format(
-			'Test' if os.path.dirname(sys.argv[0]) == 'test' else 'Spawned' ))
-
 	else:
 		sys.stdout.write( c.purple((f'NONZERO_EXIT[{exit_val}]: ' if exit_val else '') + exc_line) + '\n' )
 

+ 0 - 1
test/cmdtest_py_d/ct_misc.py

@@ -169,7 +169,6 @@ class CmdTestHelp(CmdTestBase):
 
 	def usage(self):
 		t = self.spawn('mmgen-walletgen',['foo'])
-		t.expect('MMGenSystemExit(1)')
 		t.expect('USAGE: mmgen-walletgen')
 		t.req_exit_val = 1
 		return t

+ 2 - 2
test/tooltest2.py

@@ -100,9 +100,9 @@ def fork_cmd(cmd_name,args,opts,stdin_input):
 		vmsg(cp.stderr.strip().decode())
 	if cp.returncode != 0:
 		import re
-		m = re.search(b'tool command returned (None|False)',cp.stdout)
+		m = re.search(b'tool command returned (None|False)',cp.stderr)
 		if m:
-			return { b'None': None, b'False': False }[m.group(1)]
+			return eval(m.group(1))
 		else:
 			die(2,f'Spawned program exited with error: {cp.stderr}')