3 #include "prelexer.hpp"
4 #include "backtrace.hpp"
5 #include "error_handling.hpp"
13 Base::Base(ParserState pstate, std::string msg, std::vector<Sass_Import_Entry>* import_stack)
14 : std::runtime_error(msg), msg(msg),
15 prefix("Error"), pstate(pstate),
16 import_stack(import_stack)
19 InvalidSass::InvalidSass(ParserState pstate, std::string msg)
24 InvalidParent::InvalidParent(Selector_Ptr parent, Selector_Ptr selector)
25 : Base(selector->pstate()), parent(parent), selector(selector)
27 msg = "Invalid parent selector for \"";
28 msg += selector->to_string(Sass_Inspect_Options());
30 msg += parent->to_string(Sass_Inspect_Options());
34 InvalidArgumentType::InvalidArgumentType(ParserState pstate, std::string fn, std::string arg, std::string type, const Value_Ptr value)
35 : Base(pstate), fn(fn), arg(arg), type(type), value(value)
38 if (value) msg += value->to_string(Sass_Inspect_Options());
39 msg += "\" is not a " + type;
40 msg += " for `" + fn + "'";
43 MissingArgument::MissingArgument(ParserState pstate, std::string fn, std::string arg, std::string fntype)
44 : Base(pstate), fn(fn), arg(arg), fntype(fntype)
46 msg = fntype + " " + fn;
47 msg += " is missing argument ";
51 InvalidSyntax::InvalidSyntax(ParserState pstate, std::string msg, std::vector<Sass_Import_Entry>* import_stack)
52 : Base(pstate, msg, import_stack)
55 UndefinedOperation::UndefinedOperation(Expression_Ptr_Const lhs, Expression_Ptr_Const rhs, const std::string& op)
56 : lhs(lhs), rhs(rhs), op(op)
58 msg = def_op_msg + ": \"";
59 msg += lhs->to_string({ NESTED, 5 });
60 msg += " " + op + " ";
61 msg += rhs->to_string({ TO_SASS, 5 });
65 InvalidNullOperation::InvalidNullOperation(Expression_Ptr_Const lhs, Expression_Ptr_Const rhs, const std::string& op)
66 : UndefinedOperation(lhs, rhs, op)
68 msg = def_op_null_msg + ": \"";
69 msg += lhs->inspect();
70 msg += " " + op + " ";
71 msg += rhs->inspect();
75 ZeroDivisionError::ZeroDivisionError(const Expression& lhs, const Expression& rhs)
81 DuplicateKeyError::DuplicateKeyError(const Map& dup, const Expression& org)
82 : Base(org.pstate()), dup(dup), org(org)
84 msg = "Duplicate key ";
85 msg += dup.get_duplicate_key()->inspect();
91 TypeMismatch::TypeMismatch(const Expression& var, const std::string type)
92 : Base(var.pstate()), var(var), type(type)
94 msg = var.to_string();
100 InvalidValue::InvalidValue(const Expression& val)
101 : Base(val.pstate()), val(val)
103 msg = val.to_string();
104 msg += " isn't a valid CSS value.";
107 StackError::StackError(const AST_Node& node)
108 : Base(node.pstate()), node(node)
110 msg = "stack level too deep";
113 IncompatibleUnits::IncompatibleUnits(const Number& lhs, const Number& rhs)
116 msg = "Incompatible units: '";
123 AlphaChannelsNotEqual::AlphaChannelsNotEqual(Expression_Ptr_Const lhs, Expression_Ptr_Const rhs, const std::string& op)
124 : lhs(lhs), rhs(rhs), op(op)
126 msg = "Alpha channels must be equal: ";
127 msg += lhs->to_string({ NESTED, 5 });
128 msg += " " + op + " ";
129 msg += rhs->to_string({ NESTED, 5 });
134 SassValueError::SassValueError(ParserState pstate, OperationError& err)
135 : Base(pstate, err.what())
138 prefix = err.errtype();
144 void warn(std::string msg, ParserState pstate)
146 std::cerr << "Warning: " << msg<< std::endl;
149 void warn(std::string msg, ParserState pstate, Backtrace* bt)
151 Backtrace top(bt, pstate, "");
152 msg += top.to_string();
156 void deprecated_function(std::string msg, ParserState pstate)
158 std::string cwd(Sass::File::get_cwd());
159 std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd));
160 std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd));
161 std::string output_path(Sass::File::path_for_console(rel_path, abs_path, pstate.path));
163 std::cerr << "DEPRECATION WARNING: " << msg << std::endl;
164 std::cerr << "will be an error in future versions of Sass." << std::endl;
165 std::cerr << " on line " << pstate.line+1 << " of " << output_path << std::endl;
168 void deprecated(std::string msg, std::string msg2, ParserState pstate)
170 std::string cwd(Sass::File::get_cwd());
171 std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd));
172 std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd));
173 std::string output_path(Sass::File::path_for_console(rel_path, pstate.path, pstate.path));
175 std::cerr << "DEPRECATION WARNING on line " << pstate.line + 1;
176 if (output_path.length()) std::cerr << " of " << output_path;
177 std::cerr << ":" << std::endl;
178 std::cerr << msg << " and will be an error in future versions of Sass." << std::endl;
179 if (msg2.length()) std::cerr << msg2 << std::endl;
180 std::cerr << std::endl;
183 void deprecated_bind(std::string msg, ParserState pstate)
185 std::string cwd(Sass::File::get_cwd());
186 std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd));
187 std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd));
188 std::string output_path(Sass::File::path_for_console(rel_path, abs_path, pstate.path));
190 std::cerr << "WARNING: " << msg << std::endl;
191 std::cerr << " on line " << pstate.line+1 << " of " << output_path << std::endl;
192 std::cerr << "This will be an error in future versions of Sass." << std::endl;
195 void error(std::string msg, ParserState pstate)
197 throw Exception::InvalidSyntax(pstate, msg);
200 void error(std::string msg, ParserState pstate, Backtrace* bt)
202 Backtrace top(bt, pstate, "");
203 msg += "\n" + top.to_string();