88import warnings
99import sys
1010
11+ import reframe .utility as utility
1112
12- class ReframeError (Exception ):
13- """Base exception for soft errors.
1413
15- Soft errors may be treated by simply printing the exception's message and
16- trying to continue execution if possible.
17- """
14+ class ReframeBaseError (BaseException ):
15+ """Base exception for any ReFrame error."""
16+
17+ def __init__ (self , * args ):
18+ self ._message = str (args [0 ]) if args else None
19+
20+ @property
21+ def message (self ):
22+ return self ._message
1823
1924 def __str__ (self ):
20- ret = super (). __str__ ()
25+ ret = self . _message or ''
2126 if self .__cause__ is not None :
2227 ret += ': ' + str (self .__cause__ )
2328
2429 return ret
2530
2631
27- class ReframeFatalError ( BaseException ):
28- """A fatal framework error .
32+ class ReframeError ( ReframeBaseError , Exception ):
33+ """Base exception for soft errors .
2934
30- Execution must be aborted.
35+ Soft errors may be treated by simply printing the exception's message and
36+ trying to continue execution if possible.
3137 """
3238
33- def __str__ (self ):
34- ret = super ().__str__ ()
35- if self .__cause__ is not None :
36- ret += ': ' + str (self .__cause__ )
3739
38- return ret
40+ class ReframeFatalError (ReframeBaseError ):
41+ """A fatal framework error.
42+
43+ Execution must be aborted.
44+ """
3945
4046
4147class ReframeSyntaxError (ReframeError ):
@@ -81,7 +87,11 @@ class EnvironError(ReframeError):
8187
8288
8389class SanityError (ReframeError ):
84- """Raised to denote an error in sanity or performance checking."""
90+ """Raised to denote an error in sanity checking."""
91+
92+
93+ class PerformanceError (ReframeError ):
94+ """Raised to denote an error in performance checking."""
8595
8696
8797class PipelineError (ReframeError ):
@@ -102,37 +112,36 @@ class BuildError(ReframeError):
102112 """Raised when a build fails."""
103113
104114 def __init__ (self , stdout , stderr ):
105- self ._stdout = stdout
106- self ._stderr = stderr
107-
108- def __str__ (self ):
109- return ("standard error can be found in `%s', "
110- "standard output can be found in `%s'" % (self ._stderr ,
111- self ._stdout ))
115+ super ().__init__ ()
116+ self ._message = (
117+ "standard error can be found in `%s', "
118+ "standard output can be found in `%s'" % (stdout , stderr )
119+ )
112120
113121
114122class SpawnedProcessError (ReframeError ):
115123 """Raised when a spawned OS command has failed."""
116124
117125 def __init__ (self , command , stdout , stderr , exitcode ):
118- super ().__init__ (command , stdout , stderr , exitcode )
119- self ._command = command
120- self ._stdout = stdout
121- self ._stderr = stderr
122- self ._exitcode = exitcode
126+ super ().__init__ ()
123127
124- def __str__ (self ):
125- lines = ["command '{0}' failed with exit code {1}:" .format (
126- self ._command , self ._exitcode )]
128+ # Format message and put it in args
129+ lines = [
130+ "command '%s' failed with exit code %s:" % (command , exitcode )
131+ ]
127132 lines .append ('=== STDOUT ===' )
128- if self . _stdout :
129- lines .append (self . _stdout )
133+ if stdout :
134+ lines .append (stdout )
130135
131136 lines .append ('=== STDERR ===' )
132- if self . _stderr :
133- lines .append (self . _stderr )
137+ if stderr :
138+ lines .append (stderr )
134139
135- return '\n ' .join (lines )
140+ self ._message = '\n ' .join (lines )
141+ self ._command = command
142+ self ._stdout = stdout
143+ self ._stderr = stderr
144+ self ._exitcode = exitcode
136145
137146 @property
138147 def command (self ):
@@ -156,14 +165,8 @@ class SpawnedProcessTimeout(SpawnedProcessError):
156165
157166 def __init__ (self , command , stdout , stderr , timeout ):
158167 super ().__init__ (command , stdout , stderr , None )
159- self ._timeout = timeout
160-
161- # Reset the args to match the real ones passed to this exception
162- self .args = command , stdout , stderr , timeout
163168
164- def __str__ (self ):
165- lines = ["command '{0}' timed out after {1}s:" .format (self ._command ,
166- self ._timeout )]
169+ lines = ["command '%s' timed out after %ss:" % (command , timeout )]
167170 lines .append ('=== STDOUT ===' )
168171 if self ._stdout :
169172 lines .append (self ._stdout )
@@ -172,7 +175,8 @@ def __str__(self):
172175 if self ._stderr :
173176 lines .append (self ._stderr )
174177
175- return '\n ' .join (lines )
178+ self ._message = '\n ' .join (lines )
179+ self ._timeout = timeout
176180
177181 @property
178182 def timeout (self ):
@@ -182,22 +186,18 @@ def timeout(self):
182186class JobError (ReframeError ):
183187 """Job related errors."""
184188
185- def __init__ (self , * args , jobid = None ):
186- super ().__init__ (* args )
189+ def __init__ (self , msg = None , jobid = None ):
190+ message = '[jobid=%s]' % jobid
191+ if msg :
192+ message += ' ' + msg
193+
194+ super ().__init__ (message )
187195 self ._jobid = jobid
188196
189197 @property
190198 def jobid (self ):
191199 return self ._jobid
192200
193- def __str__ (self ):
194- prefix = '(jobid=%s)' % self ._jobid
195- msg = super ().__str__ ()
196- if self .args :
197- return prefix + ' ' + msg
198- else :
199- return prefix + msg
200-
201201
202202class JobBlockedError (JobError ):
203203 """Raised by job schedulers when a job is blocked indefinitely."""
@@ -235,21 +235,18 @@ def format_user_frame(frame):
235235 if exc_type is None :
236236 return ''
237237
238- if isinstance (exc_value , SanityError ):
239- return 'sanity error: %s' % exc_value
240-
241- if isinstance (exc_value , ReframeFatalError ):
242- exc_str = '' .join (traceback .format_exception (exc_type , exc_value , tb ))
243- return 'fatal error: %s\n %s' % (exc_value , exc_str )
244-
245238 if isinstance (exc_value , AbortTaskError ):
246239 return 'aborted due to %s' % type (exc_value .__cause__ ).__name__
247240
248- if isinstance (exc_value , BuildError ):
249- return 'build failure: %s' % exc_value
250-
251241 if isinstance (exc_value , ReframeError ):
252- return 'caught framework exception: %s' % exc_value
242+ return '%s: %s' % (utility .decamelize (exc_type .__name__ , ' ' ),
243+ exc_value )
244+
245+ if isinstance (exc_value , ReframeFatalError ):
246+ exc_str = '%s: %s' % (utility .decamelize (exc_type .__name__ , ' ' ),
247+ exc_value )
248+ tb_str = '' .join (traceback .format_exception (exc_type , exc_value , tb ))
249+ return '%s\n %s' % (exc_str , tb_str )
253250
254251 if isinstance (exc_value , KeyboardInterrupt ):
255252 return 'cancelled by user'
0 commit comments