From fcb50b093e5fb0dd7d50b7c8f6fa62760aefa9fa Mon Sep 17 00:00:00 2001 From: Adeel Date: Mon, 6 Apr 2015 14:35:59 +0300 Subject: [PATCH] Code: Don't throw from interim callback state. Lets the error propagate to libsass. This goes against the concept of fast aborting, but this way downstream user will not get a blunt exception, but receive a well-formatted JSON error. Note: this exception from importer callback's post-process handler cannot be captured by try- catch. The edit in binding.cpp is also required, because those conditions will never get satisfied anyway. Removed due to aforementioned reasons. --- src/binding.cpp | 8 -------- src/custom_importer_bridge.cpp | 4 +++- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/binding.cpp b/src/binding.cpp index 022871e1f..53f28a9e5 100644 --- a/src/binding.cpp +++ b/src/binding.cpp @@ -122,10 +122,6 @@ void ExtractOptions(Local options, void* cptr, sass_context_wrapper* ctx for (size_t i = 0; i < importers->Length(); ++i) { Local callback = Local::Cast(importers->Get(static_cast(i))); - if (!callback->IsFunction()) { - NanThrowError(NanNew("options.importer must be set to a function or array of functions")); - } - auto bridge = std::make_shared(new NanCallback(callback), ctx_w->is_sync); ctx_w->importer_bridges.push_back(bridge); @@ -147,10 +143,6 @@ void ExtractOptions(Local options, void* cptr, sass_context_wrapper* ctx Local signature = Local::Cast(signatures->Get(NanNew(i))); Local callback = Local::Cast(functions->Get(signature)); - if (!signature->IsString() || !callback->IsFunction()) { - NanThrowError(NanNew("options.functions must be a (signature -> function) hash")); - } - auto bridge = std::make_shared(new NanCallback(callback), ctx_w->is_sync); ctx_w->function_bridges.push_back(bridge); diff --git a/src/custom_importer_bridge.cpp b/src/custom_importer_bridge.cpp index 6f6815c68..db09b34ce 100644 --- a/src/custom_importer_bridge.cpp +++ b/src/custom_importer_bridge.cpp @@ -17,7 +17,9 @@ SassImportList CustomImporterBridge::post_process_return_value(Handle val Local value = array->Get(static_cast(i)); if (!value->IsObject()) { - NanThrowError(NanNew("returned array must only contain object literals")); + auto entry = sass_make_import_entry(0, 0, 0); + sass_import_set_error(entry, "returned array must only contain object literals", -1, -1); + continue; } Local object = Local::Cast(value);