Skip to content

Commit 380a85b

Browse files
authored
Merge pull request #2267 from mgreter/bugfix/error-messages
Adjust a few error messages and cleanups
2 parents 2a9f386 + 5fb20cd commit 380a85b

File tree

13 files changed

+41
-145
lines changed

13 files changed

+41
-145
lines changed

script/ci-install-compiler

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
gem install minitest
44
gem install minitap
5+
6+
pip install --user 'requests[security]'

script/ci-report-coverage

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
if [ "x$COVERAGE" = "xyes" ]; then
44

55
# exclude some directories from profiling (.libs is from autotools)
6-
export EXCLUDE_COVERAGE="--exclude src/sassc
6+
export EXCLUDE_COVERAGE="--exclude plugins
7+
--exclude sassc/sassc.c
78
--exclude src/sass-spec
89
--exclude src/.libs
910
--exclude src/debug.hpp

src/ast.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,15 @@ namespace Sass {
342342
{
343343
if (Selector_List_Ptr_Const sl = dynamic_cast<Selector_List_Ptr_Const>(this)) return *sl == rhs;
344344
if (Simple_Selector_Ptr_Const sp = dynamic_cast<Simple_Selector_Ptr_Const>(this)) return *sp == rhs;
345-
throw "invalid selector base classes to compare";
345+
throw std::runtime_error("invalid selector base classes to compare");
346346
return false;
347347
}
348348

349349
bool Selector::operator< (const Selector& rhs) const
350350
{
351351
if (Selector_List_Ptr_Const sl = dynamic_cast<Selector_List_Ptr_Const>(this)) return *sl < rhs;
352352
if (Simple_Selector_Ptr_Const sp = dynamic_cast<Simple_Selector_Ptr_Const>(this)) return *sp < rhs;
353-
throw "invalid selector base classes to compare";
353+
throw std::runtime_error("invalid selector base classes to compare");
354354
return false;
355355
}
356356

src/ast.hpp

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,6 @@ namespace Sass {
924924
typedef Environment<AST_Node_Obj> Env;
925925
typedef const char* Signature;
926926
typedef Expression_Ptr (*Native_Function)(Env&, Env&, Context&, Signature, ParserState, Backtrace*, std::vector<Selector_List_Obj>);
927-
typedef const char* Signature;
928927
class Definition : public Has_Block {
929928
public:
930929
enum Type { MIXIN, FUNCTION };
@@ -2293,12 +2292,6 @@ namespace Sass {
22932292
virtual void set_media_block(Media_Block_Ptr mb) {
22942293
media_block(mb);
22952294
}
2296-
virtual bool has_wrapped_selector() {
2297-
return false;
2298-
}
2299-
virtual bool has_placeholder() {
2300-
return false;
2301-
}
23022295
virtual bool has_parent_ref() {
23032296
return false;
23042297
}
@@ -2414,6 +2407,10 @@ namespace Sass {
24142407
return name_ == "*";
24152408
}
24162409

2410+
virtual bool has_placeholder() {
2411+
return false;
2412+
}
2413+
24172414
virtual ~Simple_Selector() = 0;
24182415
virtual Compound_Selector_Ptr unify_with(Compound_Selector_Ptr, Context&);
24192416
virtual bool has_parent_ref() { return false; };
@@ -2697,10 +2694,6 @@ namespace Sass {
26972694
if (!selector()) return false;
26982695
return selector()->has_real_parent_ref();
26992696
}
2700-
virtual bool has_wrapped_selector()
2701-
{
2702-
return true;
2703-
}
27042697
virtual unsigned long specificity()
27052698
{
27062699
return selector_ ? selector_->specificity() : 0;
@@ -2797,15 +2790,6 @@ namespace Sass {
27972790
return sum;
27982791
}
27992792

2800-
virtual bool has_wrapped_selector()
2801-
{
2802-
if (length() == 0) return false;
2803-
if (Simple_Selector_Obj ss = elements().front()) {
2804-
if (ss->has_wrapped_selector()) return true;
2805-
}
2806-
return false;
2807-
}
2808-
28092793
virtual bool has_placeholder()
28102794
{
28112795
if (length() == 0) return false;
@@ -2939,11 +2923,6 @@ namespace Sass {
29392923
if (tail_) tail_->set_media_block(mb);
29402924
if (head_) head_->set_media_block(mb);
29412925
}
2942-
virtual bool has_wrapped_selector() {
2943-
if (head_ && head_->has_wrapped_selector()) return true;
2944-
if (tail_ && tail_->has_wrapped_selector()) return true;
2945-
return false;
2946-
}
29472926
virtual bool has_placeholder() {
29482927
if (head_ && head_->has_placeholder()) return true;
29492928
if (tail_ && tail_->has_placeholder()) return true;
@@ -3061,12 +3040,6 @@ namespace Sass {
30613040
cs->set_media_block(mb);
30623041
}
30633042
}
3064-
virtual bool has_wrapped_selector() {
3065-
for (Complex_Selector_Obj cs : elements()) {
3066-
if (cs->has_wrapped_selector()) return true;
3067-
}
3068-
return false;
3069-
}
30703043
virtual bool has_placeholder() {
30713044
for (Complex_Selector_Obj cs : elements()) {
30723045
if (cs->has_placeholder()) return true;

src/context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ namespace Sass {
562562
}
563563

564564
// abort early if no content could be loaded (various reasons)
565-
if (!contents) throw "File to read not found or unreadable: " + input_path;
565+
if (!contents) throw std::runtime_error("File to read not found or unreadable: " + input_path);
566566

567567
// store entry path
568568
entry_path = abs_path;

src/eval.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ namespace Sass {
5454
{ }
5555
Eval::~Eval() { }
5656

57-
Context& Eval::context()
58-
{
59-
return ctx;
60-
}
61-
6257
Env* Eval::environment()
6358
{
6459
return exp.environment();
@@ -180,8 +175,8 @@ namespace Sass {
180175
// check if units are valid for sequence
181176
if (sass_start->unit() != sass_end->unit()) {
182177
std::stringstream msg; msg << "Incompatible units: '"
183-
<< sass_start->unit() << "' and '"
184-
<< sass_end->unit() << "'.";
178+
<< sass_end->unit() << "' and '"
179+
<< sass_start->unit() << "'.";
185180
error(msg.str(), low->pstate(), backtrace());
186181
}
187182
double start = sass_start->value();
@@ -925,7 +920,7 @@ namespace Sass {
925920
} else if (sass_value_get_tag(c_val) == SASS_WARNING) {
926921
error("warning in C function " + c->name() + ": " + sass_warning_get_message(c_val), c->pstate(), backtrace());
927922
}
928-
result = cval_to_astnode(c_val, ctx, backtrace(), c->pstate());
923+
result = cval_to_astnode(c_val, backtrace(), c->pstate());
929924

930925
exp.backtrace_stack.pop_back();
931926
sass_delete_value(c_args);
@@ -1590,7 +1585,7 @@ namespace Sass {
15901585
return SASS_MEMORY_NEW(String_Constant, pstate ? *pstate : lhs.pstate(), lstr + sep + rstr);
15911586
}
15921587

1593-
Expression_Ptr cval_to_astnode(union Sass_Value* v, Context& ctx, Backtrace* backtrace, ParserState pstate)
1588+
Expression_Ptr cval_to_astnode(union Sass_Value* v, Backtrace* backtrace, ParserState pstate)
15941589
{
15951590
using std::strlen;
15961591
using std::strcpy;
@@ -1615,16 +1610,16 @@ namespace Sass {
16151610
case SASS_LIST: {
16161611
List_Ptr l = SASS_MEMORY_NEW(List, pstate, sass_list_get_length(v), sass_list_get_separator(v));
16171612
for (size_t i = 0, L = sass_list_get_length(v); i < L; ++i) {
1618-
l->append(cval_to_astnode(sass_list_get_value(v, i), ctx, backtrace, pstate));
1613+
l->append(cval_to_astnode(sass_list_get_value(v, i), backtrace, pstate));
16191614
}
16201615
e = l;
16211616
} break;
16221617
case SASS_MAP: {
16231618
Map_Ptr m = SASS_MEMORY_NEW(Map, pstate);
16241619
for (size_t i = 0, L = sass_map_get_length(v); i < L; ++i) {
16251620
*m << std::make_pair(
1626-
cval_to_astnode(sass_map_get_key(v, i), ctx, backtrace, pstate),
1627-
cval_to_astnode(sass_map_get_value(v, i), ctx, backtrace, pstate));
1621+
cval_to_astnode(sass_map_get_key(v, i), backtrace, pstate),
1622+
cval_to_astnode(sass_map_get_value(v, i), backtrace, pstate));
16281623
}
16291624
e = m;
16301625
} break;

src/eval.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ namespace Sass {
2727
bool is_in_comment;
2828

2929
Env* environment();
30-
Context& context();
31-
Selector_List_Obj selector();
3230
Backtrace* backtrace();
31+
Selector_List_Obj selector();
3332

3433
// for evaluating function bodies
3534
Expression_Ptr operator()(Block_Ptr);
@@ -103,7 +102,7 @@ namespace Sass {
103102

104103
};
105104

106-
Expression_Ptr cval_to_astnode(union Sass_Value* v, Context& ctx, Backtrace* backtrace, ParserState pstate = ParserState("[AST]"));
105+
Expression_Ptr cval_to_astnode(union Sass_Value* v, Backtrace* backtrace, ParserState pstate = ParserState("[AST]"));
107106

108107
}
109108

src/extend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,11 +1627,11 @@ namespace Sass {
16271627
SourcesSet debugSet;
16281628
debugSet = pNewSelector->sources();
16291629
if (debugSet.size() > 0) {
1630-
throw "The new selector should start with no sources. Something needs to be cloned to fix this.";
1630+
throw std::runtime_error("The new selector should start with no sources. Something needs to be cloned to fix this.");
16311631
}
16321632
debugSet = pExtComplexSelector->sources();
16331633
if (debugSet.size() > 0) {
1634-
throw "The extension selector from our subset map should not have sources. These will bleed to the new selector. Something needs to be cloned to fix this.";
1634+
throw std::runtime_error("The extension selector from our subset map should not have sources. These will bleed to the new selector. Something needs to be cloned to fix this.");
16351635
}
16361636
#endif
16371637

src/functions.cpp

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,6 @@ namespace Sass {
170170
return Parser::parse_selector(exp_src.c_str(), ctx);
171171
}
172172

173-
template <>
174-
Complex_Selector_Obj get_arg_sel(const std::string& argname, Env& env, Signature sig, ParserState pstate, Backtrace* backtrace, Context& ctx) {
175-
Expression_Obj exp = ARG(argname, Expression);
176-
if (exp->concrete_type() == Expression::NULL_VAL) {
177-
std::stringstream msg;
178-
msg << argname << ": null is not a valid selector: it must be a string,\n";
179-
msg << "a list of strings, or a list of lists of strings for `" << function_name(sig) << "'";
180-
error(msg.str(), pstate);
181-
}
182-
if (String_Constant_Ptr str = SASS_MEMORY_CAST(String_Constant, exp)) {
183-
str->quote_mark(0);
184-
}
185-
std::string exp_src = exp->to_string(ctx.c_options) + "{";
186-
Selector_List_Obj sel_list = Parser::parse_selector(exp_src.c_str(), ctx);
187-
return (sel_list->length() > 0) ? &sel_list->first() : 0;
188-
}
189-
190173
template <>
191174
Compound_Selector_Obj get_arg_sel(const std::string& argname, Env& env, Signature sig, ParserState pstate, Backtrace* backtrace, Context& ctx) {
192175
Expression_Obj exp = ARG(argname, Expression);
@@ -702,7 +685,7 @@ namespace Sass {
702685
bool hsl = h || s || l;
703686

704687
if (rgb && hsl) {
705-
error("cannot specify both RGB and HSL values for `adjust-color`", pstate);
688+
error("Cannot specify HSL and RGB values for a color at the same time for `adjust-color'", pstate);
706689
}
707690
if (rgb) {
708691
double rr = r ? ARGR("$red", Number, -255, 255)->value() : 0;
@@ -736,7 +719,7 @@ namespace Sass {
736719
color->b(),
737720
color->a() + (a ? a->value() : 0));
738721
}
739-
error("not enough arguments for `adjust-color`", pstate);
722+
error("not enough arguments for `adjust-color'", pstate);
740723
// unreachable
741724
return color;
742725
}
@@ -757,7 +740,7 @@ namespace Sass {
757740
bool hsl = h || s || l;
758741

759742
if (rgb && hsl) {
760-
error("cannot specify both RGB and HSL values for `scale-color`", pstate);
743+
error("Cannot specify HSL and RGB values for a color at the same time for `scale-color'", pstate);
761744
}
762745
if (rgb) {
763746
double rscale = (r ? ARGR("$red", Number, -100.0, 100.0)->value() : 0.0) / 100.0;
@@ -792,7 +775,7 @@ namespace Sass {
792775
color->b(),
793776
color->a() + ascale * (ascale > 0.0 ? 1.0 - color->a() : color->a()));
794777
}
795-
error("not enough arguments for `scale-color`", pstate);
778+
error("not enough arguments for `scale-color'", pstate);
796779
// unreachable
797780
return color;
798781
}
@@ -813,7 +796,7 @@ namespace Sass {
813796
bool hsl = h || s || l;
814797

815798
if (rgb && hsl) {
816-
error("cannot specify both RGB and HSL values for `change-color`", pstate);
799+
error("Cannot specify HSL and RGB values for a color at the same time for `change-color'", pstate);
817800
}
818801
if (rgb) {
819802
return SASS_MEMORY_NEW(Color,
@@ -840,7 +823,7 @@ namespace Sass {
840823
color->b(),
841824
alpha);
842825
}
843-
error("not enough arguments for `change-color`", pstate);
826+
error("not enough arguments for `change-color'", pstate);
844827
// unreachable
845828
return color;
846829
}
@@ -1201,13 +1184,13 @@ namespace Sass {
12011184
double v = l->value();
12021185
if (v < 1) {
12031186
stringstream err;
1204-
err << "$limit " << v << " must be greater than or equal to 1 for `random`";
1187+
err << "$limit " << v << " must be greater than or equal to 1 for `random'";
12051188
error(err.str(), pstate);
12061189
}
12071190
bool eq_int = std::fabs(trunc(v) - v) < NUMBER_EPSILON;
12081191
if (!eq_int) {
12091192
stringstream err;
1210-
err << "Expected $limit to be an integer but got `" << v << "` for `random`";
1193+
err << "Expected $limit to be an integer but got " << v << " for `random'";
12111194
error(err.str(), pstate);
12121195
}
12131196
std::uniform_real_distribution<> distributor(1, v + 1);
@@ -1771,7 +1754,7 @@ namespace Sass {
17711754

17721755
// Not enough parameters
17731756
if( arglist->length() == 0 )
1774-
error("$selectors: At least one selector must be passed", pstate);
1757+
error("$selectors: At least one selector must be passed for `selector-nest'", pstate);
17751758

17761759
// Parse args into vector of selectors
17771760
std::vector<Selector_List_Obj> parsedSelectors;
@@ -1824,7 +1807,7 @@ namespace Sass {
18241807

18251808
// Not enough parameters
18261809
if( arglist->length() == 0 )
1827-
error("$selectors: At least one selector must be passed", pstate);
1810+
error("$selectors: At least one selector must be passed for `selector-append'", pstate);
18281811

18291812
// Parse args into vector of selectors
18301813
std::vector<Selector_List_Obj> parsedSelectors;
@@ -1873,22 +1856,22 @@ namespace Sass {
18731856

18741857
// Must be a simple sequence
18751858
if( childSeq->combinator() != Complex_Selector::Combinator::ANCESTOR_OF ) {
1876-
std::string msg("Can't append `");
1859+
std::string msg("Can't append \"");
18771860
msg += childSeq->to_string();
1878-
msg += "` to `";
1861+
msg += "\" to \"";
18791862
msg += parentSeqClone->to_string();
1880-
msg += "`";
1863+
msg += "\" for `selector-append'";
18811864
error(msg, pstate, backtrace);
18821865
}
18831866

18841867
// Cannot be a Universal selector
18851868
Element_Selector_Obj pType = SASS_MEMORY_CAST(Element_Selector, childSeq->head()->first());
18861869
if(pType && pType->name() == "*") {
1887-
std::string msg("Can't append `");
1870+
std::string msg("Can't append \"");
18881871
msg += childSeq->to_string();
1889-
msg += "` to `";
1872+
msg += "\" to \"";
18901873
msg += parentSeqClone->to_string();
1891-
msg += "`";
1874+
msg += "\" for `selector-append'";
18921875
error(msg, pstate, backtrace);
18931876
}
18941877

src/parser.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,16 +1016,6 @@ namespace Sass {
10161016
{
10171017
Expression_Obj key = parse_list();
10181018
List_Obj map = SASS_MEMORY_NEW(List, pstate, 0, SASS_HASH);
1019-
if (String_Quoted_Ptr str = SASS_MEMORY_CAST(String_Quoted, key)) {
1020-
if (!str->quote_mark() && !str->is_delayed()) {
1021-
if (Color_Ptr_Const col = name_to_color(str->value())) {
1022-
Color_Ptr c = SASS_MEMORY_NEW(Color, col); // copy
1023-
c->pstate(str->pstate());
1024-
c->disp(str->value());
1025-
key = c;
1026-
}
1027-
}
1028-
}
10291019

10301020
// it's not a map so return the lexed value as a list value
10311021
if (!lex_css< exactly<':'> >())
@@ -1043,16 +1033,6 @@ namespace Sass {
10431033
{ break; }
10441034

10451035
Expression_Obj key = parse_space_list();
1046-
if (String_Quoted_Ptr str = SASS_MEMORY_CAST(String_Quoted, key)) {
1047-
if (!str->quote_mark() && !str->is_delayed()) {
1048-
if (Color_Ptr_Const col = name_to_color(str->value())) {
1049-
Color_Ptr c = SASS_MEMORY_NEW(Color, col); // copy
1050-
c->pstate(str->pstate());
1051-
c->disp(str->value());
1052-
key = c;
1053-
}
1054-
}
1055-
}
10561036

10571037
if (!(lex< exactly<':'> >()))
10581038
{ css_error("Invalid CSS", " after ", ": expected \":\", was "); }

0 commit comments

Comments
 (0)