Skip to content

Commit

Permalink
Handling exceptions.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wbyoung committed Jun 30, 2015
1 parent 19d7375 commit 3db73b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,15 @@ void Database::FunctionExecute(FunctionBaton *baton, FunctionInvocation *invocat
argv.push_back(arg);
}

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

// process the result
if (result->IsString() || result->IsRegExp()) {
if (trycatch.HasCaught()) {
String::Utf8Value message(trycatch.Message()->Get());
sqlite3_result_error(context, *message, message.length());
}
else if (result->IsString() || result->IsRegExp()) {
String::Utf8Value value(result->ToString());
sqlite3_result_text(context, *value, value.length(), SQLITE_TRANSIENT);
}
Expand Down
4 changes: 2 additions & 2 deletions test/user_functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ describe('user functions', function() {
});
});

it.skip('reports errors thrown in functions', function(done) {
it('reports errors thrown in functions', function(done) {
db.all('SELECT MY_ERROR() AS val', function(err, rows) {
assert.equal(err.message, 'This function always throws');
assert.equal(err.message, 'SQLITE_ERROR: Uncaught Error: This function always throws');
assert.equal(rows, undefined);
done();
});
Expand Down

0 comments on commit 3db73b9

Please sign in to comment.