Skip to content

Commit 1559cf5

Browse files
authored
Merge pull request #319 from smoors/error
add EESSIError exception to avoid printing traceback
2 parents b6db076 + 7eb682e commit 1559cf5

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

eessi/testsuite/eessi_mixin.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from reframe.core.backends import getlauncher
44
from reframe.core.builtins import parameter, run_after, run_before, variable
5-
from reframe.core.exceptions import ReframeFatalError
65
from reframe.core.logging import getlogger
76
try:
87
from reframe.core.pipeline import RegressionTestPlugin
@@ -12,8 +11,8 @@
1211
import reframe.utility.sanity as sn
1312

1413
from eessi.testsuite import check_process_binding, hooks
15-
from eessi.testsuite.constants import DEVICE_TYPES, SCALES, COMPUTE_UNITS, TAGS
16-
from eessi.testsuite.utils import log, log_once
14+
from eessi.testsuite.constants import COMPUTE_UNITS, DEVICE_TYPES, SCALES, TAGS
15+
from eessi.testsuite.utils import EESSIError, log, log_once
1716
from eessi.testsuite import __version__ as testsuite_version
1817

1918

@@ -108,7 +107,7 @@ def EESSI_mixin_validate_item_in_list(self, item, valid_items):
108107
msg = f"The variable '{item}' has value {value}, but the only valid value is {valid_items[0]}"
109108
else:
110109
msg = f"The variable '{item}' has value {value}, but the only valid values are {valid_items}"
111-
raise ReframeFatalError(msg)
110+
raise EESSIError(msg)
112111

113112
@run_after('init')
114113
def EESSI_check_readonly_files(self):
@@ -121,7 +120,7 @@ def EESSI_check_readonly_files(self):
121120
"set `readonly_files = ['']`. To symlink all files in `sourcesdir`, set `all_readonly_files = True`.",
122121
])
123122
if self.readonly_files_undefined_policy == 'error':
124-
raise ReframeFatalError(msg)
123+
raise EESSIError(msg)
125124
log_once(self, msg, msg_id='1', level=self.readonly_files_undefined_policy)
126125

127126
@run_after('init')
@@ -143,7 +142,7 @@ def EESSI_mixin_validate_init(self):
143142
if not hasattr(self, var):
144143
msg = "The variable '%s' should be defined in any test class that inherits" % var
145144
msg += " from EESSI_Mixin before (or in) the init phase, but it wasn't"
146-
raise ReframeFatalError(msg)
145+
raise EESSIError(msg)
147146

148147
# Check that the value for these variables is valid,
149148
# i.e. exists in their respective dict from eessi.testsuite.constants
@@ -173,7 +172,7 @@ def EESSI_mixin_run_after_init(self):
173172
hooks.set_compact_thread_binding(self)
174173
elif thread_binding != 'false':
175174
err_msg = f"Invalid thread_binding value '{thread_binding}'. Valid values: 'true', 'compact', or 'false'."
176-
raise ReframeFatalError(err_msg)
175+
raise EESSIError(err_msg)
177176

178177
hooks.filter_valid_systems_by_device_type(self, required_device_type=self.device_type)
179178

@@ -212,7 +211,7 @@ def EESSI_mixin_validate_setup(self):
212211
if not hasattr(self, var):
213212
msg = "The variable '%s' should be defined in any test class that inherits" % var
214213
msg += " from EESSI_Mixin before (or in) the setup phase, but it wasn't"
215-
raise ReframeFatalError(msg)
214+
raise EESSIError(msg)
216215

217216
# Check if mem_func was defined to compute the required memory per node as function of the number of
218217
# tasks per node
@@ -222,7 +221,7 @@ def EESSI_mixin_validate_setup(self):
222221
msg += " can use self.num_tasks_per_node, as it will be called after that attribute"
223222
msg += " has been set."
224223
if self.required_mem_per_node_undefined_policy == 'error':
225-
raise ReframeFatalError(msg)
224+
raise EESSIError(msg)
226225
log_once(self, msg, msg_id='2', level=self.required_mem_per_node_undefined_policy)
227226

228227
# Check that the value for these variables is valid

eessi/testsuite/utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import inspect
66
import os
77
import re
8+
import sys
89
from typing import Iterator, List
910

1011
import reframe as rfm
@@ -34,6 +35,18 @@
3435
pass
3536

3637

38+
class EESSIError(ReframeFatalError):
39+
traceback = os.getenv('TRACEBACK', "0")
40+
addendum = ''
41+
if traceback.lower() not in ('1', 'true', 'yes', 'on'):
42+
# don't show traceback for EESSI errors
43+
sys.tracebacklimit = 0
44+
addendum = '\nRerun with `TRACEBACK=1 reframe ...` to show the full traceback.'
45+
46+
def __str__(self):
47+
return super().__str__() + EESSIError.addendum
48+
49+
3750
def log(msg, logger=printer.debug):
3851
funcname = inspect.currentframe().f_back.f_code.co_name
3952
logger(f'[{funcname}]: {msg}')
@@ -128,7 +141,7 @@ def get_avail_modules() -> List[str]:
128141
log(f"Total number of available modules: {len(_available_modules)}")
129142
if not _available_modules:
130143
msg = 'No available modules found on the system.'
131-
raise ReframeFatalError(msg)
144+
raise EESSIError(msg)
132145
return _available_modules
133146

134147

0 commit comments

Comments
 (0)