Commit 50f374df by Adeel

Code: Throws Error object.

* Returns json-string error from LibSass as is.
* Extends empty error object with parsed JSON.

Note: The reason why  NanError  is not used
because LibSass returns error as JSON string
with  message  as member, so we would have to
reparse and reassign the obj in that case.

Issue URL: #675.
PR URL: #668.
parent 82df99d2
var fs = require('fs'),
path = require('path');
path = require('path'),
util = require('util');
require('./extensions');
......@@ -146,12 +147,9 @@ function getOptions(options) {
var error = options.error;
var success = options.success;
options.error = function(err, code) {
err = JSON.parse(err);
err.code = code;
options.error = function(err) {
if (error) {
error(err);
error(util._extend(new Error(), JSON.parse(err)));
}
};
......@@ -246,6 +244,8 @@ module.exports.renderSync = function(options) {
return result;
}
throw util._extend(new Error(), JSON.parse(result.error));
};
/**
......
......@@ -197,17 +197,19 @@ void GetSourceMap(sass_context_wrapper* ctx_w, Sass_Context* ctx) {
NanNew(ctx_w->result)->Set(NanNew("map"), source_map);
}
int GetResult(sass_context_wrapper* ctx_w, Sass_Context* ctx) {
int GetResult(sass_context_wrapper* ctx_w, Sass_Context* ctx, bool is_sync = false) {
NanScope();
int status = sass_context_get_error_status(ctx);
if (status == 0) {
NanNew(ctx_w->result)->Set(NanNew("css"), NanNew<String>(sass_context_get_output_string(ctx)));
GetStats(ctx_w, ctx);
GetSourceMap(ctx_w, ctx);
}
else if (is_sync) {
NanNew(ctx_w->result)->Set(NanNew("error"), NanNew<String>(sass_context_get_error_json(ctx)));
}
return status;
}
......@@ -236,10 +238,9 @@ void make_callback(uv_work_t* req) {
// if error, do callback(error)
const char* err = sass_context_get_error_json(ctx);
Local<Value> argv[] = {
NanNew<String>(err),
NanNew<Integer>(status)
NanNew<String>(err)
};
ctx_w->error_callback->Call(2, argv);
ctx_w->error_callback->Call(1, argv);
}
if (try_catch.HasCaught()) {
node::FatalException(try_catch);
......@@ -282,19 +283,10 @@ NAN_METHOD(RenderSync) {
compile_data(dctx);
int result = GetResult(ctx_w, ctx);
Local<String> error;
if (result != 0) {
error = NanNew<String>(sass_context_get_error_json(ctx));
}
int result = GetResult(ctx_w, ctx, true);
sass_wrapper_dispose(ctx_w, source_string);
if (result != 0) {
NanThrowError(error);
}
NanReturnValue(NanNew<Boolean>(result == 0));
}
......@@ -327,19 +319,10 @@ NAN_METHOD(RenderFileSync) {
ExtractOptions(options, fctx, ctx_w, true, true);
compile_file(fctx);
int result = GetResult(ctx_w, ctx);
Local<String> error;
if (result != 0) {
error = NanNew<String>(sass_context_get_error_json(ctx));
}
int result = GetResult(ctx_w, ctx, true);
sass_wrapper_dispose(ctx_w, input_path);
if (result != 0) {
NanThrowError(error);
}
NanReturnValue(NanNew<Boolean>(result == 0));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment