Skip to content

Commit 6635326

Browse files
committed
Improve error handling in C-API to be more robust
It's possible that another throw happens in error handling. One case is invalid utf8 in error messages that json wants to stringify. We could wire it up to handle arbitrary level of nested throws, but that could lead to endless loops, so I opted to only wire it for one additional level.
1 parent dad3022 commit 6635326

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/sass_context.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extern "C" {
3636
type sass_context_take_##option (struct Sass_Context* ctx) \
3737
{ type foo = ctx->option; ctx->option = 0; return foo; }
3838

39-
static int handle_errors(Sass_Context* c_ctx) {
39+
static int handle_error(Sass_Context* c_ctx) {
4040
try {
4141
throw;
4242
}
@@ -194,6 +194,14 @@ extern "C" {
194194
return c_ctx->error_status;
195195
}
196196

197+
// allow one error handler to throw another error
198+
// this can happen with invalid utf8 and json lib
199+
static int handle_errors(Sass_Context* c_ctx) {
200+
try { return handle_error(c_ctx); }
201+
catch (...) { return handle_error(c_ctx); }
202+
return c_ctx->error_status;
203+
}
204+
197205
// generic compilation function (not exported, use file/data compile instead)
198206
static Sass_Compiler* sass_prepare_context (Sass_Context* c_ctx, Context* cpp_ctx) throw()
199207
{

0 commit comments

Comments
 (0)