1 #ifndef SASS_ERROR_HANDLING_H
2 #define SASS_ERROR_HANDLING_H
7 #include "position.hpp"
15 const std::string def_msg = "Invalid sass detected";
16 const std::string def_op_msg = "Undefined operation";
17 const std::string def_op_null_msg = "Invalid null operation";
19 class Base : public std::runtime_error {
25 std::vector<Sass_Import_Entry>* import_stack;
27 Base(ParserState pstate, std::string msg = def_msg, std::vector<Sass_Import_Entry>* import_stack = 0);
28 virtual const char* errtype() const { return prefix.c_str(); }
29 virtual const char* what() const throw() { return msg.c_str(); }
30 virtual ~Base() throw() {};
33 class InvalidSass : public Base {
35 InvalidSass(ParserState pstate, std::string msg);
36 virtual ~InvalidSass() throw() {};
39 class InvalidParent : public Base {
42 Selector_Ptr selector;
44 InvalidParent(Selector_Ptr parent, Selector_Ptr selector);
45 virtual ~InvalidParent() throw() {};
48 class MissingArgument : public Base {
54 MissingArgument(ParserState pstate, std::string fn, std::string arg, std::string fntype);
55 virtual ~MissingArgument() throw() {};
58 class InvalidArgumentType : public Base {
63 const Value_Ptr value;
65 InvalidArgumentType(ParserState pstate, std::string fn, std::string arg, std::string type, const Value_Ptr value = 0);
66 virtual ~InvalidArgumentType() throw() {};
69 class InvalidSyntax : public Base {
71 InvalidSyntax(ParserState pstate, std::string msg, std::vector<Sass_Import_Entry>* import_stack = 0);
72 virtual ~InvalidSyntax() throw() {};
75 /* common virtual base class (has no pstate) */
76 class OperationError : public std::runtime_error {
80 OperationError(std::string msg = def_op_msg)
81 : std::runtime_error(msg), msg(msg)
84 virtual const char* errtype() const { return "Error"; }
85 virtual const char* what() const throw() { return msg.c_str(); }
86 virtual ~OperationError() throw() {};
89 class ZeroDivisionError : public OperationError {
91 const Expression& lhs;
92 const Expression& rhs;
94 ZeroDivisionError(const Expression& lhs, const Expression& rhs);
95 virtual const char* errtype() const { return "ZeroDivisionError"; }
96 virtual ~ZeroDivisionError() throw() {};
99 class DuplicateKeyError : public Base {
102 const Expression& org;
104 DuplicateKeyError(const Map& dup, const Expression& org);
105 virtual const char* errtype() const { return "Error"; }
106 virtual ~DuplicateKeyError() throw() {};
109 class TypeMismatch : public Base {
111 const Expression& var;
112 const std::string type;
114 TypeMismatch(const Expression& var, const std::string type);
115 virtual const char* errtype() const { return "Error"; }
116 virtual ~TypeMismatch() throw() {};
119 class InvalidValue : public Base {
121 const Expression& val;
123 InvalidValue(const Expression& val);
124 virtual const char* errtype() const { return "Error"; }
125 virtual ~InvalidValue() throw() {};
128 class StackError : public Base {
130 const AST_Node& node;
132 StackError(const AST_Node& node);
133 virtual const char* errtype() const { return "SystemStackError"; }
134 virtual ~StackError() throw() {};
137 class IncompatibleUnits : public OperationError {
142 IncompatibleUnits(const Number& lhs, const Number& rhs);
143 virtual ~IncompatibleUnits() throw() {};
146 class UndefinedOperation : public OperationError {
148 Expression_Ptr_Const lhs;
149 Expression_Ptr_Const rhs;
150 const std::string op;
152 UndefinedOperation(Expression_Ptr_Const lhs, Expression_Ptr_Const rhs, const std::string& op);
153 // virtual const char* errtype() const { return "Error"; }
154 virtual ~UndefinedOperation() throw() {};
157 class InvalidNullOperation : public UndefinedOperation {
159 InvalidNullOperation(Expression_Ptr_Const lhs, Expression_Ptr_Const rhs, const std::string& op);
160 virtual ~InvalidNullOperation() throw() {};
163 class AlphaChannelsNotEqual : public OperationError {
165 Expression_Ptr_Const lhs;
166 Expression_Ptr_Const rhs;
167 const std::string op;
169 AlphaChannelsNotEqual(Expression_Ptr_Const lhs, Expression_Ptr_Const rhs, const std::string& op);
170 // virtual const char* errtype() const { return "Error"; }
171 virtual ~AlphaChannelsNotEqual() throw() {};
174 class SassValueError : public Base {
176 SassValueError(ParserState pstate, OperationError& err);
177 virtual ~SassValueError() throw() {};
182 void warn(std::string msg, ParserState pstate);
183 void warn(std::string msg, ParserState pstate, Backtrace* bt);
185 void deprecated_function(std::string msg, ParserState pstate);
186 void deprecated(std::string msg, std::string msg2, ParserState pstate);
187 void deprecated_bind(std::string msg, ParserState pstate);
188 // void deprecated(std::string msg, ParserState pstate, Backtrace* bt);
190 void error(std::string msg, ParserState pstate);
191 void error(std::string msg, ParserState pstate, Backtrace* bt);