1515import reframe
1616import reframe .core .config as config
1717import reframe .core .environments as env
18+ import reframe .core .exceptions as errors
1819import reframe .core .logging as logging
1920import reframe .core .runtime as runtime
21+ import reframe .core .warnings as warnings
2022import reframe .frontend .argparse as argparse
2123import reframe .frontend .check_filters as filters
2224import reframe .frontend .dependency as dependency
2325import reframe .utility .jsonext as jsonext
2426import reframe .utility .osext as osext
25- from reframe .core .exceptions import (
26- EnvironError , ConfigError , ReframeError ,
27- ReframeFatalError , format_exception
28- )
29- from reframe .core .warnings import ReframeDeprecationWarning
3027from reframe .frontend .executors import Runner , generate_testcases
3128from reframe .frontend .executors .policies import (SerialExecutionPolicy ,
3229 AsynchronousExecutionPolicy )
@@ -453,7 +450,7 @@ def main():
453450 try :
454451 try :
455452 site_config = config .load_config (options .config_file )
456- except ReframeDeprecationWarning as e :
453+ except warnings . ReframeDeprecationWarning as e :
457454 printer .warning (e )
458455 converted = config .convert_old_config (options .config_file )
459456 printer .warning (
@@ -483,7 +480,7 @@ def main():
483480 options .update_config (site_config )
484481
485482 logging .configure_logging (site_config )
486- except (OSError , ConfigError ) as e :
483+ except (OSError , errors . ConfigError ) as e :
487484 printer .error (f'failed to load configuration: { e } ' )
488485 sys .exit (1 )
489486
@@ -492,7 +489,7 @@ def main():
492489 printer .inc_verbosity (site_config .get ('general/0/verbose' ))
493490 try :
494491 runtime .init_runtime (site_config )
495- except ConfigError as e :
492+ except errors . ConfigError as e :
496493 printer .error (f'failed to initialize runtime: { e } ' )
497494 sys .exit (1 )
498495
@@ -507,7 +504,7 @@ def main():
507504 for m in site_config .get ('general/0/module_mappings' ):
508505 rt .modules_system .load_mapping (m )
509506
510- except (ConfigError , OSError ) as e :
507+ except (errors . ConfigError , OSError ) as e :
511508 printer .error ('could not load module mappings: %s' % e )
512509 sys .exit (1 )
513510
@@ -580,7 +577,7 @@ def print_infoline(param, value):
580577 try :
581578 checks_found = loader .load_all ()
582579 except OSError as e :
583- raise ReframeError from e
580+ raise errors . ReframeError from e
584581
585582 # Filter checks by name
586583 checks_matched = checks_found
@@ -651,7 +648,7 @@ def print_infoline(param, value):
651648 # Load the environment for the current system
652649 try :
653650 runtime .loadenv (rt .system .preload_environ )
654- except EnvironError as e :
651+ except errors . EnvironError as e :
655652 printer .error ("failed to load current system's environment; "
656653 "please check your configuration" )
657654 printer .debug (str (e ))
@@ -660,7 +657,7 @@ def print_infoline(param, value):
660657 for m in site_config .get ('general/0/user_modules' ):
661658 try :
662659 rt .modules_system .load_module (m , force = True )
663- except EnvironError as e :
660+ except errors . EnvironError as e :
664661 printer .warning ("could not load module '%s' correctly: "
665662 "Skipping..." % m )
666663 printer .debug (str (e ))
@@ -695,7 +692,9 @@ def print_infoline(param, value):
695692 errmsg = "invalid option for --flex-alloc-nodes: '{0}'"
696693 sched_flex_alloc_nodes = int (options .flex_alloc_nodes )
697694 if sched_flex_alloc_nodes <= 0 :
698- raise ConfigError (errmsg .format (options .flex_alloc_nodes ))
695+ raise errors .ConfigError (
696+ errmsg .format (options .flex_alloc_nodes )
697+ )
699698 except ValueError :
700699 sched_flex_alloc_nodes = options .flex_alloc_nodes
701700
@@ -713,8 +712,9 @@ def print_infoline(param, value):
713712 try :
714713 max_retries = int (options .max_retries )
715714 except ValueError :
716- raise ConfigError ('--max-retries is not a valid integer: %s' %
717- max_retries ) from None
715+ raise errors .ConfigError (
716+ f'--max-retries is not a valid integer: { max_retries } '
717+ ) from None
718718 runner = Runner (exec_policy , printer , max_retries )
719719 try :
720720 time_start = time .time ()
@@ -735,10 +735,10 @@ def print_infoline(param, value):
735735
736736 # Print a failure report if we had failures in the last run
737737 if runner .stats .failures ():
738- printer . info ( runner .stats .failure_report () )
738+ runner .stats .print_failure_report ( printer )
739739 success = False
740740 if options .failure_stats :
741- printer . info ( runner .stats .failure_stats () )
741+ runner .stats .print_failure_stats ( printer )
742742
743743 if options .performance_report :
744744 printer .info (runner .stats .performance_report ())
@@ -784,11 +784,18 @@ def print_infoline(param, value):
784784
785785 except KeyboardInterrupt :
786786 sys .exit (1 )
787- except ReframeError as e :
787+ except errors . ReframeError as e :
788788 printer .error (str (e ))
789789 sys .exit (1 )
790- except (Exception , ReframeFatalError ):
791- printer .error (format_exception (* sys .exc_info ()))
790+ except (Exception , errors .ReframeFatalError ):
791+ exc_info = sys .exc_info ()
792+ tb = '' .join (traceback .format_exception (* exc_info ))
793+ printer .error (errors .what (* exc_info ))
794+ if errors .is_severe (* exc_info ):
795+ printer .error (tb )
796+ else :
797+ printer .verbose (tb )
798+
792799 sys .exit (1 )
793800 finally :
794801 try :
@@ -797,7 +804,7 @@ def print_infoline(param, value):
797804 log_files = logging .save_log_files (rt .output_prefix )
798805
799806 except OSError as e :
800- printer .error ('could not save log file: %s' % e )
807+ printer .error (f 'could not save log file: { e } ' )
801808 sys .exit (1 )
802809 finally :
803810 if not log_files :
0 commit comments