1
2 """Standardized Error Messages"""
3
4 import traceback
5 import sys
6
7 from PyFoam.Basics.TerminalFormatter import TerminalFormatter
8 from PyFoam.ThirdParty.six import print_
9
10 defaultFormat=TerminalFormatter()
11 defaultFormat.getConfigFormat("error")
12 defaultFormat.getConfigFormat("warning",shortName="warn")
13
15 try:
16 f = traceback.extract_stack(limit=up+2)
17 if f:
18 return f[0]
19 except:
20 if __debug__:
21 traceback.print_exc()
22 pass
23 return ('', 0, '', None)
24
26 """Common function for errors and Warnings"""
27 info=getLine(up=2)
28 if format and sys.stderr.isatty():
29 print_(format, end=' ', file=sys.stderr)
30 print_("PyFoam",standard.upper(),"on line",info[1],"of file",info[0],":", end=' ', file=sys.stderr)
31 for t in text:
32 print_(t, end=' ', file=sys.stderr)
33
34 if sys.stderr.isatty():
35 print_(defaultFormat.reset, file=sys.stderr)
36
38 """Prints a warning message with the occuring line number
39 @param text: The error message"""
40 __common(defaultFormat.warn,"Warning",*text)
41
47
53
55 """Prints a debug message with the occuring line number
56 @param text: The error message"""
57 __common(None,"Debug",*text)
58
60 """Prints a 'not implemented' message for abstract interfaces
61 @param obj: the object for which the method is not defined
62 @param name: name of the method"""
63 error("The method",name,"is not implemented in this object of type",obj.__class__)
64
66 """The simplest exception for PyFoam"""
67
69 self.descr=text[0]
70 for t in text[1:]:
71 self.descr+=" "+str(t)
72
74 return "Problem in PyFoam: '"+self.descr+"'"
75
77 """The PyFoam-exception that does not expect to be caught"""
78
84
86 return "FatalError in PyFoam: '"+self.descr+"'"
87
88
89