1 | //----------------------------------------------------------- |
---|
2 | // Copyright Christian Arnault LAL-Orsay CNRS |
---|
3 | // arnault@lal.in2p3.fr |
---|
4 | // Modified by garonne@lal.in2p3.fr |
---|
5 | // Modified by Grigory Rybkin |
---|
6 | // See the complete license in cmt_license.txt "http://www.cecill.info". |
---|
7 | //----------------------------------------------------------- |
---|
8 | |
---|
9 | #include "cmt_error.h" |
---|
10 | #include "cmt_vector.h" |
---|
11 | #include "cmt_log.h" |
---|
12 | |
---|
13 | class TheError |
---|
14 | { |
---|
15 | public: |
---|
16 | static TheError& instance (); |
---|
17 | |
---|
18 | TheError () |
---|
19 | { |
---|
20 | error_names.add() = "ok"; |
---|
21 | error_names.add() = "warning"; |
---|
22 | error_names.add() = "symbol not found"; |
---|
23 | error_names.add() = "pattern not found"; |
---|
24 | error_names.add() = "constituent not found"; |
---|
25 | error_names.add() = "fragment not found"; |
---|
26 | error_names.add() = "language not found"; |
---|
27 | error_names.add() = "syntax error"; |
---|
28 | error_names.add() = "command not implemented"; |
---|
29 | error_names.add() = "package not found"; |
---|
30 | error_names.add() = "path not found"; |
---|
31 | error_names.add() = "version conflict"; |
---|
32 | error_names.add() = "file access error"; |
---|
33 | error_names.add() = "system error"; |
---|
34 | error_names.add() = "configuration error"; |
---|
35 | error_names.add() = "execution error"; |
---|
36 | error_names.add() = "cannot lock"; |
---|
37 | error_names.add() = "cannot_write_lock"; |
---|
38 | error_names.add() = "cannot_run_lock_command"; |
---|
39 | error_names.add() = "cannot_unlock"; |
---|
40 | error_names.add() = "cannot_run_unlock_command"; |
---|
41 | error_names.add() = "cannot_remove_lock"; |
---|
42 | error_names.add() = "conflicting_lock"; |
---|
43 | error_names.add() = "unknown command"; |
---|
44 | error_names.add() = "wrong symbol type"; |
---|
45 | error_names.add() = "project release conflict"; |
---|
46 | error_names.add() = "execution failed"; |
---|
47 | m_execution_error = 0; |
---|
48 | } |
---|
49 | |
---|
50 | ~TheError () |
---|
51 | { |
---|
52 | } |
---|
53 | |
---|
54 | void clear () |
---|
55 | { |
---|
56 | m_code = CmtError::ok; |
---|
57 | m_text = ""; |
---|
58 | m_execution_error = 0 ; |
---|
59 | } |
---|
60 | |
---|
61 | void set (CmtError::code code, const cmt_string& text, const int execution_error) |
---|
62 | { |
---|
63 | m_code = code; |
---|
64 | m_text = text; |
---|
65 | m_execution_error = execution_error; |
---|
66 | } |
---|
67 | |
---|
68 | CmtError::code get_code () const |
---|
69 | { |
---|
70 | return (m_code); |
---|
71 | } |
---|
72 | |
---|
73 | int get_last_execution_error () |
---|
74 | { |
---|
75 | return m_execution_error; |
---|
76 | } |
---|
77 | |
---|
78 | const cmt_string& get_text () const |
---|
79 | { |
---|
80 | return (m_text); |
---|
81 | } |
---|
82 | |
---|
83 | const cmt_string& get_name (CmtError::code error) const |
---|
84 | { |
---|
85 | const cmt_string& s = error_names[error]; |
---|
86 | |
---|
87 | return (s); |
---|
88 | } |
---|
89 | |
---|
90 | private: |
---|
91 | CmtError::code m_code; |
---|
92 | cmt_string m_text; |
---|
93 | cmt_vector<cmt_string> error_names; |
---|
94 | int m_execution_error; |
---|
95 | }; |
---|
96 | |
---|
97 | //--------------------------------------------------------------- |
---|
98 | TheError& TheError::instance () |
---|
99 | { |
---|
100 | static TheError e; |
---|
101 | |
---|
102 | return (e); |
---|
103 | } |
---|
104 | |
---|
105 | //--------------------------------------------------------------- |
---|
106 | void CmtError::clear () |
---|
107 | { |
---|
108 | TheError& e = TheError::instance (); |
---|
109 | |
---|
110 | e.clear (); |
---|
111 | } |
---|
112 | |
---|
113 | //--------------------------------------------------------------- |
---|
114 | bool CmtError::has_pending_error () |
---|
115 | { |
---|
116 | TheError& e = TheError::instance (); |
---|
117 | |
---|
118 | if (e.get_code () == ok) return (false); |
---|
119 | else return (true); |
---|
120 | } |
---|
121 | |
---|
122 | //--------------------------------------------------------------- |
---|
123 | CmtError::code CmtError::get_last_error_code () |
---|
124 | { |
---|
125 | TheError& e = TheError::instance (); |
---|
126 | |
---|
127 | return (e.get_code ()); |
---|
128 | } |
---|
129 | |
---|
130 | //--------------------------------------------------------------- |
---|
131 | int CmtError::get_last_execution_error () |
---|
132 | { |
---|
133 | TheError& e = TheError::instance (); |
---|
134 | |
---|
135 | return (e.get_last_execution_error ()); |
---|
136 | } |
---|
137 | |
---|
138 | //--------------------------------------------------------------- |
---|
139 | const cmt_string& CmtError::get_error_name (code error) |
---|
140 | { |
---|
141 | TheError& e = TheError::instance (); |
---|
142 | |
---|
143 | return (e.get_name (error)); |
---|
144 | } |
---|
145 | |
---|
146 | //--------------------------------------------------------------- |
---|
147 | void CmtError::set (code error, const cmt_string& text, const int execution_error) |
---|
148 | { |
---|
149 | TheError& e = TheError::instance (); |
---|
150 | |
---|
151 | e.set (error, text, execution_error); |
---|
152 | } |
---|
153 | |
---|
154 | //--------------------------------------------------------------- |
---|
155 | cmt_string CmtError::get_last_error () |
---|
156 | { |
---|
157 | TheError& e = TheError::instance (); |
---|
158 | |
---|
159 | cmt_string result; |
---|
160 | |
---|
161 | result = get_error_name (e.get_code ()); |
---|
162 | result += ": "; |
---|
163 | result += e.get_text (); |
---|
164 | |
---|
165 | return (result); |
---|
166 | } |
---|
167 | |
---|
168 | //--------------------------------------------------------------- |
---|
169 | void CmtError::print () |
---|
170 | { |
---|
171 | /* |
---|
172 | TheError& e = TheError::instance (); |
---|
173 | |
---|
174 | cerr << "CMT> Error: " << get_error_name (e.get_code ()) << " : " << e.get_text () << endl; |
---|
175 | */ |
---|
176 | if (CmtError::get_last_error_code () != CmtError::warning) |
---|
177 | CmtMessage::error (get_last_error ()); |
---|
178 | else |
---|
179 | CmtMessage::warning (get_last_error ()); |
---|
180 | } |
---|
181 | |
---|