Skip to content

Commit 6d6e4c7

Browse files
committed
More fixups
1 parent 83d38e4 commit 6d6e4c7

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

src/bind.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ namespace Sass {
246246

247247
if (!param_map.count(param)) {
248248
std::stringstream msg;
249-
msg << callee << " has no parameter named " << param;
249+
msg << "No argument named " << param << ".";
250250
error(msg.str(), a->pstate(), traces);
251251
}
252252
env->local_frame()[param] = argmap->at(key);
@@ -275,7 +275,7 @@ namespace Sass {
275275
varargs->append(a);
276276
} else {
277277
std::stringstream msg;
278-
msg << callee << " has no parameter named " << a->name();
278+
msg << "No argument named " << a->name() << ".";
279279
error(msg.str(), a->pstate(), traces);
280280
}
281281
}

src/fn_colors.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ namespace Sass {
473473
else if (hsl) {
474474
Color_HSLA_Obj c = col->copyAsHSLA();
475475
if (h) c->h(c->h() + absmod(h->value(), 360.0));
476-
if (s) c->s(c->s() + DARG_R_PRCT("$saturation"));
477-
if (l) c->l(c->l() + DARG_R_PRCT("$lightness"));
476+
if (s) c->s(c->s() + DARG_R_CENT("$saturation"));
477+
if (l) c->l(c->l() + DARG_R_CENT("$lightness"));
478478
if (a) c->a(c->a() + DARG_R_FACT("$alpha"));
479479
return c.detach();
480480
}

src/fn_colors.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Sass {
1414
#define DARG_R_BYTE(argname) get_arg_r(argname, env, sig, pstate, traces, - 255.0, 255.0) // double
1515
#define DARG_U_PRCT(argname) get_arg_r(argname, env, sig, pstate, traces, 0.0, 100.0) // double
1616
#define DARG_R_PRCT(argname) get_arg_r(argname, env, sig, pstate, traces, - 100.0, 100.0, "%") // double
17+
#define DARG_R_CENT(argname) get_arg_r(argname, env, sig, pstate, traces, - 100.0, 100.0) // double
1718

1819
// macros for color related inputs (rbg and alpha/opacity values)
1920
#define COLOR_NUM(argname) color_num(argname, env, sig, pstate, traces) // double

src/fn_lists.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,19 @@ namespace Sass {
7171
bool empty = m ? m->empty() : sl->empty();
7272
if (empty) error("argument `$list` of `" + std::string(sig) + "` must not be empty", pstate, traces);
7373
double index = std::floor(nr < 0 ? len + nr : nr - 1);
74-
if (index < 0 || index > len - 1) error("index out of bounds for `" + std::string(sig) + "`", pstate, traces);
74+
if (index < 0 || index > len - 1) {
75+
if (index == -1) error("$n: List index may not be 0.", pstate, traces);
76+
std::stringstream strm;
77+
strm << "$n: Invalid index ";
78+
strm << (index + 1);
79+
strm << " for a list with ";
80+
strm << len << " elements.";
81+
error(strm.str(), pstate, traces);
82+
}
7583
return Cast<Value>(Listize::perform(sl->get(static_cast<int>(index))));
7684
}
7785
List_Obj l = Cast<List>(env["$list"]);
78-
if (nr == 0) error("argument `$n` of `" + std::string(sig) + "` must be non-zero", pstate, traces);
86+
if (nr == 0) error("$n: List index may not be 0.", pstate, traces);
7987
// if the argument isn't a list, then wrap it in a singleton list
8088
if (!m && !l) {
8189
l = SASS_MEMORY_NEW(List, pstate, 1);
@@ -85,7 +93,15 @@ namespace Sass {
8593
bool empty = m ? m->empty() : l->empty();
8694
if (empty) error("argument `$list` of `" + std::string(sig) + "` must not be empty", pstate, traces);
8795
double index = std::floor(nr < 0 ? len + nr : nr - 1);
88-
if (index < 0 || index > len - 1) error("index out of bounds for `" + std::string(sig) + "`", pstate, traces);
96+
if (index < 0 || index > len - 1) {
97+
if (index == -1) error("$n: List index may not be 0.", pstate, traces);
98+
std::stringstream strm;
99+
strm << "$n: Invalid index ";
100+
strm << (index + 1);
101+
strm << " for a list with ";
102+
strm << l->length() << " elements.";
103+
error(strm.str(), pstate, traces);
104+
}
89105

90106
if (m) {
91107
l = SASS_MEMORY_NEW(List, pstate, 2);
@@ -116,7 +132,15 @@ namespace Sass {
116132
}
117133
if (l->empty()) error("argument `$list` of `" + std::string(sig) + "` must not be empty", pstate, traces);
118134
double index = std::floor(n->value() < 0 ? l->length() + n->value() : n->value() - 1);
119-
if (index < 0 || index > l->length() - 1) error("index out of bounds for `" + std::string(sig) + "`", pstate, traces);
135+
if (index < 0 || index > l->length() - 1) {
136+
if (index == -1) error("$n: List index may not be 0.", pstate, traces);
137+
std::stringstream strm;
138+
strm << "$n: Invalid index ";
139+
strm << (index + 1);
140+
strm << " for a list with ";
141+
strm << l->length() << " elements.";
142+
error(strm.str(), pstate, traces);
143+
}
120144
List* result = SASS_MEMORY_NEW(List, pstate, l->length(), l->separator(), false, l->is_bracketed());
121145
for (size_t i = 0, L = l->length(); i < L; ++i) {
122146
result->append(((i == index) ? v : (*l)[i]));
@@ -181,7 +205,7 @@ namespace Sass {
181205
std::string sep_str = unquote(sep->value());
182206
if (sep_str == "space") sep_val = SASS_SPACE;
183207
else if (sep_str == "comma") sep_val = SASS_COMMA;
184-
else if (sep_str != "auto") error("argument `$separator` of `" + std::string(sig) + "` must be `space`, `comma`, or `auto`", pstate, traces);
208+
else if (sep_str != "auto") error("$separator: Must be \"space\", \"comma\", or \"auto\".", pstate, traces);
185209

186210
if (l1) { l1sep = l1->separator(); }
187211
if (l2) { l2sep = l2->separator(); }
@@ -242,7 +266,7 @@ namespace Sass {
242266
if (sep_str != "auto") { // check default first
243267
if (sep_str == "space") result->separator(SASS_SPACE);
244268
else if (sep_str == "comma") result->separator(SASS_COMMA);
245-
else error("argument `$separator` of `" + std::string(sig) + "` must be `space`, `comma`, or `auto`", pstate, traces);
269+
else error("$separator: Must be \"space\", \"comma\", or \"auto\".", pstate, traces);
246270
}
247271
if (l->is_arglist()) {
248272
result->append(SASS_MEMORY_NEW(Argument,

src/fn_numbers.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace Sass {
6060
BUILT_IN(percentage)
6161
{
6262
Number_Obj n = ARGN("$number");
63-
if (!n->is_unitless()) error("argument $number of `" + std::string(sig) + "` must be unitless", pstate, traces);
63+
if (!n->is_unitless()) error("Exprected " + n->to_string() + " to have no units.", pstate, traces);
6464
return SASS_MEMORY_NEW(Number, pstate, n->value() * 100, "%");
6565
}
6666

@@ -161,7 +161,7 @@ namespace Sass {
161161
bool eq_int = std::fabs(trunc(lv) - lv) < NUMBER_EPSILON;
162162
if (!eq_int) {
163163
std::stringstream err;
164-
err << "Expected $limit to be an integer but got " << lv << " for `random'";
164+
err << "$limit: " << lv << " is not an int.";
165165
error(err.str(), pstate, traces);
166166
}
167167
std::uniform_real_distribution<> distributor(1, lv + 1);
@@ -207,11 +207,11 @@ namespace Sass {
207207
return SASS_MEMORY_NEW(Boolean, pstate, unitless);
208208
}
209209

210-
Signature comparable_sig = "comparable($number-1, $number-2)";
210+
Signature comparable_sig = "comparable($number1, $number2)";
211211
BUILT_IN(comparable)
212212
{
213-
Number_Obj n1 = ARGN("$number-1");
214-
Number_Obj n2 = ARGN("$number-2");
213+
Number_Obj n1 = ARGN("$number1");
214+
Number_Obj n2 = ARGN("$number2");
215215
if (n1->is_unitless() || n2->is_unitless()) {
216216
return SASS_MEMORY_NEW(Boolean, pstate, true);
217217
}

0 commit comments

Comments
 (0)