1 | #ifndef SASS_ERROR_HANDLING_H |
2 | #define SASS_ERROR_HANDLING_H |
3 | |
4 | // sass.hpp must go before all system headers to get the |
5 | // __EXTENSIONS__ fix on Solaris. |
6 | #include "sass.hpp" |
7 | |
8 | #include <string> |
9 | #include <sstream> |
10 | #include <stdexcept> |
11 | #include "units.hpp" |
12 | #include "position.hpp" |
13 | #include "backtrace.hpp" |
14 | #include "ast_fwd_decl.hpp" |
15 | #include "sass/functions.h" |
16 | |
17 | namespace Sass { |
18 | |
19 | struct Backtrace; |
20 | |
21 | namespace Exception { |
22 | |
23 | const sass::string def_msg = "Invalid sass detected" ; |
24 | const sass::string def_op_msg = "Undefined operation" ; |
25 | const sass::string def_op_null_msg = "Invalid null operation" ; |
26 | const sass::string def_nesting_limit = "Code too deeply nested" ; |
27 | |
28 | class Base : public std::runtime_error { |
29 | protected: |
30 | sass::string msg; |
31 | sass::string prefix; |
32 | public: |
33 | SourceSpan pstate; |
34 | Backtraces traces; |
35 | public: |
36 | Base(SourceSpan pstate, sass::string msg, Backtraces traces); |
37 | virtual const char* errtype() const { return prefix.c_str(); } |
38 | virtual const char* what() const throw() { return msg.c_str(); } |
39 | virtual ~Base() throw() {}; |
40 | }; |
41 | |
42 | class InvalidSass : public Base { |
43 | public: |
44 | InvalidSass(SourceSpan pstate, Backtraces traces, sass::string msg); |
45 | virtual ~InvalidSass() throw() {}; |
46 | }; |
47 | |
48 | class InvalidParent : public Base { |
49 | protected: |
50 | Selector* parent; |
51 | Selector* selector; |
52 | public: |
53 | InvalidParent(Selector* parent, Backtraces traces, Selector* selector); |
54 | virtual ~InvalidParent() throw() {}; |
55 | }; |
56 | |
57 | class MissingArgument : public Base { |
58 | protected: |
59 | sass::string fn; |
60 | sass::string arg; |
61 | sass::string fntype; |
62 | public: |
63 | MissingArgument(SourceSpan pstate, Backtraces traces, sass::string fn, sass::string arg, sass::string fntype); |
64 | virtual ~MissingArgument() throw() {}; |
65 | }; |
66 | |
67 | class InvalidArgumentType : public Base { |
68 | protected: |
69 | sass::string fn; |
70 | sass::string arg; |
71 | sass::string type; |
72 | const Value* value; |
73 | public: |
74 | InvalidArgumentType(SourceSpan pstate, Backtraces traces, sass::string fn, sass::string arg, sass::string type, const Value* value = 0); |
75 | virtual ~InvalidArgumentType() throw() {}; |
76 | }; |
77 | |
78 | class InvalidVarKwdType : public Base { |
79 | protected: |
80 | sass::string name; |
81 | const Argument* arg; |
82 | public: |
83 | InvalidVarKwdType(SourceSpan pstate, Backtraces traces, sass::string name, const Argument* arg = 0); |
84 | virtual ~InvalidVarKwdType() throw() {}; |
85 | }; |
86 | |
87 | class InvalidSyntax : public Base { |
88 | public: |
89 | InvalidSyntax(SourceSpan pstate, Backtraces traces, sass::string msg); |
90 | virtual ~InvalidSyntax() throw() {}; |
91 | }; |
92 | |
93 | class NestingLimitError : public Base { |
94 | public: |
95 | NestingLimitError(SourceSpan pstate, Backtraces traces, sass::string msg = def_nesting_limit); |
96 | virtual ~NestingLimitError() throw() {}; |
97 | }; |
98 | |
99 | class DuplicateKeyError : public Base { |
100 | protected: |
101 | const Map& dup; |
102 | const Expression& org; |
103 | public: |
104 | DuplicateKeyError(Backtraces traces, const Map& dup, const Expression& org); |
105 | virtual const char* errtype() const { return "Error" ; } |
106 | virtual ~DuplicateKeyError() throw() {}; |
107 | }; |
108 | |
109 | class TypeMismatch : public Base { |
110 | protected: |
111 | const Expression& var; |
112 | const sass::string type; |
113 | public: |
114 | TypeMismatch(Backtraces traces, const Expression& var, const sass::string type); |
115 | virtual const char* errtype() const { return "Error" ; } |
116 | virtual ~TypeMismatch() throw() {}; |
117 | }; |
118 | |
119 | class InvalidValue : public Base { |
120 | protected: |
121 | const Expression& val; |
122 | public: |
123 | InvalidValue(Backtraces traces, const Expression& val); |
124 | virtual const char* errtype() const { return "Error" ; } |
125 | virtual ~InvalidValue() throw() {}; |
126 | }; |
127 | |
128 | class StackError : public Base { |
129 | protected: |
130 | const AST_Node& node; |
131 | public: |
132 | StackError(Backtraces traces, const AST_Node& node); |
133 | virtual const char* errtype() const { return "SystemStackError" ; } |
134 | virtual ~StackError() throw() {}; |
135 | }; |
136 | |
137 | /* common virtual base class (has no pstate or trace) */ |
138 | class OperationError : public std::runtime_error { |
139 | protected: |
140 | sass::string msg; |
141 | public: |
142 | OperationError(sass::string msg = def_op_msg) |
143 | : std::runtime_error(msg.c_str()), msg(msg) |
144 | {}; |
145 | public: |
146 | virtual const char* errtype() const { return "Error" ; } |
147 | virtual const char* what() const throw() { return msg.c_str(); } |
148 | virtual ~OperationError() throw() {}; |
149 | }; |
150 | |
151 | class ZeroDivisionError : public OperationError { |
152 | protected: |
153 | const Expression& lhs; |
154 | const Expression& rhs; |
155 | public: |
156 | ZeroDivisionError(const Expression& lhs, const Expression& rhs); |
157 | virtual const char* errtype() const { return "ZeroDivisionError" ; } |
158 | virtual ~ZeroDivisionError() throw() {}; |
159 | }; |
160 | |
161 | class IncompatibleUnits : public OperationError { |
162 | protected: |
163 | // const Sass::UnitType lhs; |
164 | // const Sass::UnitType rhs; |
165 | public: |
166 | IncompatibleUnits(const Units& lhs, const Units& rhs); |
167 | IncompatibleUnits(const UnitType lhs, const UnitType rhs); |
168 | virtual ~IncompatibleUnits() throw() {}; |
169 | }; |
170 | |
171 | class UndefinedOperation : public OperationError { |
172 | protected: |
173 | const Expression* lhs; |
174 | const Expression* rhs; |
175 | const Sass_OP op; |
176 | public: |
177 | UndefinedOperation(const Expression* lhs, const Expression* rhs, enum Sass_OP op); |
178 | // virtual const char* errtype() const { return "Error"; } |
179 | virtual ~UndefinedOperation() throw() {}; |
180 | }; |
181 | |
182 | class InvalidNullOperation : public UndefinedOperation { |
183 | public: |
184 | InvalidNullOperation(const Expression* lhs, const Expression* rhs, enum Sass_OP op); |
185 | virtual ~InvalidNullOperation() throw() {}; |
186 | }; |
187 | |
188 | class AlphaChannelsNotEqual : public OperationError { |
189 | protected: |
190 | const Expression* lhs; |
191 | const Expression* rhs; |
192 | const Sass_OP op; |
193 | public: |
194 | AlphaChannelsNotEqual(const Expression* lhs, const Expression* rhs, enum Sass_OP op); |
195 | // virtual const char* errtype() const { return "Error"; } |
196 | virtual ~AlphaChannelsNotEqual() throw() {}; |
197 | }; |
198 | |
199 | class SassValueError : public Base { |
200 | public: |
201 | SassValueError(Backtraces traces, SourceSpan pstate, OperationError& err); |
202 | virtual ~SassValueError() throw() {}; |
203 | }; |
204 | |
205 | class TopLevelParent : public Base { |
206 | public: |
207 | TopLevelParent(Backtraces traces, SourceSpan pstate); |
208 | virtual ~TopLevelParent() throw() {}; |
209 | }; |
210 | |
211 | class UnsatisfiedExtend : public Base { |
212 | public: |
213 | UnsatisfiedExtend(Backtraces traces, Extension extension); |
214 | virtual ~UnsatisfiedExtend() throw() {}; |
215 | }; |
216 | |
217 | class ExtendAcrossMedia : public Base { |
218 | public: |
219 | ExtendAcrossMedia(Backtraces traces, Extension extension); |
220 | virtual ~ExtendAcrossMedia() throw() {}; |
221 | }; |
222 | |
223 | } |
224 | |
225 | void warn(sass::string msg, SourceSpan pstate); |
226 | void warn(sass::string msg, SourceSpan pstate, Backtrace* bt); |
227 | void warning(sass::string msg, SourceSpan pstate); |
228 | |
229 | void deprecated_function(sass::string msg, SourceSpan pstate); |
230 | void deprecated(sass::string msg, sass::string msg2, bool with_column, SourceSpan pstate); |
231 | void deprecated_bind(sass::string msg, SourceSpan pstate); |
232 | // void deprecated(sass::string msg, SourceSpan pstate, Backtrace* bt); |
233 | |
234 | void coreError(sass::string msg, SourceSpan pstate); |
235 | void error(sass::string msg, SourceSpan pstate, Backtraces& traces); |
236 | |
237 | } |
238 | |
239 | #endif |
240 | |