Blame src/error_handling.cpp

Packit Service 7770af
#include "sass.hpp"
Packit Service 7770af
#include "ast.hpp"
Packit Service 7770af
#include "prelexer.hpp"
Packit Service 7770af
#include "backtrace.hpp"
Packit Service 7770af
#include "error_handling.hpp"
Packit Service 7770af
Packit Service 7770af
#include <iostream>
Packit Service 7770af
Packit Service 7770af
namespace Sass {
Packit Service 7770af
Packit Service 7770af
  namespace Exception {
Packit Service 7770af
Packit Service 7770af
    Base::Base(ParserState pstate, std::string msg, std::vector<Sass_Import_Entry>* import_stack)
Packit Service 7770af
    : std::runtime_error(msg), msg(msg),
Packit Service 7770af
      prefix("Error"), pstate(pstate),
Packit Service 7770af
      import_stack(import_stack)
Packit Service 7770af
    { }
Packit Service 7770af
Packit Service 7770af
    InvalidSass::InvalidSass(ParserState pstate, std::string msg)
Packit Service 7770af
    : Base(pstate, msg)
Packit Service 7770af
    { }
Packit Service 7770af
Packit Service 7770af
Packit Service 7770af
    InvalidParent::InvalidParent(Selector_Ptr parent, Selector_Ptr selector)
Packit Service 7770af
    : Base(selector->pstate()), parent(parent), selector(selector)
Packit Service 7770af
    {
Packit Service 7770af
      msg = "Invalid parent selector for \"";
Packit Service 7770af
      msg += selector->to_string(Sass_Inspect_Options());
Packit Service 7770af
      msg += "\": \"";
Packit Service 7770af
      msg += parent->to_string(Sass_Inspect_Options());
Packit Service 7770af
      msg += "\"";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    InvalidVarKwdType::InvalidVarKwdType(ParserState pstate, std::string name, const Argument_Ptr arg)
Packit Service 7770af
    : Base(pstate), name(name), arg(arg)
Packit Service 7770af
    {
Packit Service 7770af
      msg = "Variable keyword argument map must have string keys.\n";
Packit Service 7770af
      msg += name + " is not a string in " + arg->to_string() + ".";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    InvalidArgumentType::InvalidArgumentType(ParserState pstate, std::string fn, std::string arg, std::string type, const Value_Ptr value)
Packit Service 7770af
    : Base(pstate), fn(fn), arg(arg), type(type), value(value)
Packit Service 7770af
    {
Packit Service 7770af
      msg  = arg + ": \"";
Packit Service 7770af
      if (value) msg += value->to_string(Sass_Inspect_Options());
Packit Service 7770af
      msg += "\" is not a " + type;
Packit Service 7770af
      msg += " for `" + fn + "'";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    MissingArgument::MissingArgument(ParserState pstate, std::string fn, std::string arg, std::string fntype)
Packit Service 7770af
    : Base(pstate), fn(fn), arg(arg), fntype(fntype)
Packit Service 7770af
    {
Packit Service 7770af
      msg  = fntype + " " + fn;
Packit Service 7770af
      msg += " is missing argument ";
Packit Service 7770af
      msg += arg + ".";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    InvalidSyntax::InvalidSyntax(ParserState pstate, std::string msg, std::vector<Sass_Import_Entry>* import_stack)
Packit Service 7770af
    : Base(pstate, msg, import_stack)
Packit Service 7770af
    { }
Packit Service 7770af
Packit Service 7770af
    UndefinedOperation::UndefinedOperation(Expression_Ptr_Const lhs, Expression_Ptr_Const rhs, const std::string& op)
Packit Service 7770af
    : lhs(lhs), rhs(rhs), op(op)
Packit Service 7770af
    {
Packit Service 7770af
      msg  = def_op_msg + ": \"";
Packit Service 7770af
      msg += lhs->to_string({ NESTED, 5 });
Packit Service 7770af
      msg += " " + op + " ";
Packit Service 7770af
      msg += rhs->to_string({ TO_SASS, 5 });
Packit Service 7770af
      msg += "\".";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    InvalidNullOperation::InvalidNullOperation(Expression_Ptr_Const lhs, Expression_Ptr_Const rhs, const std::string& op)
Packit Service 7770af
    : UndefinedOperation(lhs, rhs, op)
Packit Service 7770af
    {
Packit Service 7770af
      msg  = def_op_null_msg + ": \"";
Packit Service 7770af
      msg += lhs->inspect();
Packit Service 7770af
      msg += " " + op + " ";
Packit Service 7770af
      msg += rhs->inspect();
Packit Service 7770af
      msg += "\".";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    ZeroDivisionError::ZeroDivisionError(const Expression& lhs, const Expression& rhs)
Packit Service 7770af
    : lhs(lhs), rhs(rhs)
Packit Service 7770af
    {
Packit Service 7770af
      msg  = "divided by 0";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    DuplicateKeyError::DuplicateKeyError(const Map& dup, const Expression& org)
Packit Service 7770af
    : Base(org.pstate()), dup(dup), org(org)
Packit Service 7770af
    {
Packit Service 7770af
      msg  = "Duplicate key ";
Packit Service 7770af
      msg += dup.get_duplicate_key()->inspect();
Packit Service 7770af
      msg += " in map (";
Packit Service 7770af
      msg += org.inspect();
Packit Service 7770af
      msg += ").";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    TypeMismatch::TypeMismatch(const Expression& var, const std::string type)
Packit Service 7770af
    : Base(var.pstate()), var(var), type(type)
Packit Service 7770af
    {
Packit Service 7770af
      msg  = var.to_string();
Packit Service 7770af
      msg += " is not an ";
Packit Service 7770af
      msg += type;
Packit Service 7770af
      msg += ".";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    InvalidValue::InvalidValue(const Expression& val)
Packit Service 7770af
    : Base(val.pstate()), val(val)
Packit Service 7770af
    {
Packit Service 7770af
      msg  = val.to_string();
Packit Service 7770af
      msg += " isn't a valid CSS value.";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    StackError::StackError(const AST_Node& node)
Packit Service 7770af
    : Base(node.pstate()), node(node)
Packit Service 7770af
    {
Packit Service 7770af
      msg  = "stack level too deep";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    IncompatibleUnits::IncompatibleUnits(const Number& lhs, const Number& rhs)
Packit Service 7770af
    {
Packit Service 7770af
      msg  = "Incompatible units: '";
Packit Service 7770af
      msg += rhs.unit();
Packit Service 7770af
      msg += "' and '";
Packit Service 7770af
      msg += lhs.unit();
Packit Service 7770af
      msg += "'.";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    IncompatibleUnits::IncompatibleUnits(const UnitType lhs, const UnitType rhs)
Packit Service 7770af
    {
Packit Service 7770af
      msg  = "Incompatible units: '";
Packit Service 7770af
      msg += unit_to_string(rhs);
Packit Service 7770af
      msg += "' and '";
Packit Service 7770af
      msg += unit_to_string(lhs);
Packit Service 7770af
      msg += "'.";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
    AlphaChannelsNotEqual::AlphaChannelsNotEqual(Expression_Ptr_Const lhs, Expression_Ptr_Const rhs, const std::string& op)
Packit Service 7770af
    : lhs(lhs), rhs(rhs), op(op)
Packit Service 7770af
    {
Packit Service 7770af
      msg  = "Alpha channels must be equal: ";
Packit Service 7770af
      msg += lhs->to_string({ NESTED, 5 });
Packit Service 7770af
      msg += " " + op + " ";
Packit Service 7770af
      msg += rhs->to_string({ NESTED, 5 });
Packit Service 7770af
      msg += ".";
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
Packit Service 7770af
    SassValueError::SassValueError(ParserState pstate, OperationError& err)
Packit Service 7770af
    : Base(pstate, err.what())
Packit Service 7770af
    {
Packit Service 7770af
      msg = err.what();
Packit Service 7770af
      prefix = err.errtype();
Packit Service 7770af
    }
Packit Service 7770af
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
Packit Service 7770af
  void warn(std::string msg, ParserState pstate)
Packit Service 7770af
  {
Packit Service 7770af
    std::cerr << "Warning: " << msg<< std::endl;
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void warn(std::string msg, ParserState pstate, Backtrace* bt)
Packit Service 7770af
  {
Packit Service 7770af
    Backtrace top(bt, pstate, "");
Packit Service 7770af
    msg += top.to_string();
Packit Service 7770af
    warn(msg, pstate);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void deprecated_function(std::string msg, ParserState pstate)
Packit Service 7770af
  {
Packit Service 7770af
    std::string cwd(Sass::File::get_cwd());
Packit Service 7770af
    std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd));
Packit Service 7770af
    std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd));
Packit Service 7770af
    std::string output_path(Sass::File::path_for_console(rel_path, abs_path, pstate.path));
Packit Service 7770af
Packit Service 7770af
    std::cerr << "DEPRECATION WARNING: " << msg << std::endl;
Packit Service 7770af
    std::cerr << "will be an error in future versions of Sass." << std::endl;
Packit Service 7770af
    std::cerr << "        on line " << pstate.line+1 << " of " << output_path << std::endl;
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void deprecated(std::string msg, std::string msg2, ParserState pstate)
Packit Service 7770af
  {
Packit Service 7770af
    std::string cwd(Sass::File::get_cwd());
Packit Service 7770af
    std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd));
Packit Service 7770af
    std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd));
Packit Service 7770af
    std::string output_path(Sass::File::path_for_console(rel_path, pstate.path, pstate.path));
Packit Service 7770af
Packit Service 7770af
    std::cerr << "DEPRECATION WARNING on line " << pstate.line + 1;
Packit Service 7770af
    if (output_path.length()) std::cerr << " of " << output_path;
Packit Service 7770af
    std::cerr << ":" << std::endl;
Packit Service 7770af
    std::cerr << msg << " and will be an error in future versions of Sass." << std::endl;
Packit Service 7770af
    if (msg2.length()) std::cerr << msg2 << std::endl;
Packit Service 7770af
    std::cerr << std::endl;
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void deprecated_bind(std::string msg, ParserState pstate)
Packit Service 7770af
  {
Packit Service 7770af
    std::string cwd(Sass::File::get_cwd());
Packit Service 7770af
    std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd));
Packit Service 7770af
    std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd));
Packit Service 7770af
    std::string output_path(Sass::File::path_for_console(rel_path, abs_path, pstate.path));
Packit Service 7770af
Packit Service 7770af
    std::cerr << "WARNING: " << msg << std::endl;
Packit Service 7770af
    std::cerr << "        on line " << pstate.line+1 << " of " << output_path << std::endl;
Packit Service 7770af
    std::cerr << "This will be an error in future versions of Sass." << std::endl;
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void error(std::string msg, ParserState pstate)
Packit Service 7770af
  {
Packit Service 7770af
    throw Exception::InvalidSyntax(pstate, msg);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
  void error(std::string msg, ParserState pstate, Backtrace* bt)
Packit Service 7770af
  {
Packit Service 7770af
    Backtrace top(bt, pstate, "");
Packit Service 7770af
    msg += "\n" + top.to_string();
Packit Service 7770af
    error(msg, pstate);
Packit Service 7770af
  }
Packit Service 7770af
Packit Service 7770af
}