Skip to content

Commit 3db73b9

Browse files
committed
Handling exceptions.
I believe this is the most appropriate way to handle exceptions. Using v8::Function::Call rather than node::MakeCallback (via NanMakeCallback) means that these functions will not work with domains, but that seems appropriate. I don't know if nodejs/node-v0.x-archive#9245 or nodejs/nan#284 should be a concern here or not.
1 parent 19d7375 commit 3db73b9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/database.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,15 @@ void Database::FunctionExecute(FunctionBaton *baton, FunctionInvocation *invocat
475475
argv.push_back(arg);
476476
}
477477

478-
Local<Value> result = TRY_CATCH_CALL(NanObjectWrapHandle(db), cb, argc, argv.data());
478+
TryCatch trycatch;
479+
Local<Value> result = cb->Call(NanObjectWrapHandle(db), argc, argv.data());
479480

480481
// process the result
481-
if (result->IsString() || result->IsRegExp()) {
482+
if (trycatch.HasCaught()) {
483+
String::Utf8Value message(trycatch.Message()->Get());
484+
sqlite3_result_error(context, *message, message.length());
485+
}
486+
else if (result->IsString() || result->IsRegExp()) {
482487
String::Utf8Value value(result->ToString());
483488
sqlite3_result_text(context, *value, value.length(), SQLITE_TRANSIENT);
484489
}

test/user_functions.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ describe('user functions', function() {
7777
});
7878
});
7979

80-
it.skip('reports errors thrown in functions', function(done) {
80+
it('reports errors thrown in functions', function(done) {
8181
db.all('SELECT MY_ERROR() AS val', function(err, rows) {
82-
assert.equal(err.message, 'This function always throws');
82+
assert.equal(err.message, 'SQLITE_ERROR: Uncaught Error: This function always throws');
8383
assert.equal(rows, undefined);
8484
done();
8585
});

0 commit comments

Comments
 (0)