Unverified Commit 88e3ec6c authored by Tyler Wanek's avatar Tyler Wanek Committed by GitHub

Merge pull request #1393 from rcjsuen/errorFunction

Expose JavaScript function name in a rejected promise
parents 708b9dd8 63f2dac2
...@@ -315,6 +315,7 @@ var Helpers = { ...@@ -315,6 +315,7 @@ var Helpers = {
fnDef.cppFunctionName = Helpers.cTypeToCppName(key, "git_" + typeDef.typeName); fnDef.cppFunctionName = Helpers.cTypeToCppName(key, "git_" + typeDef.typeName);
fnDef.jsFunctionName = Helpers.cTypeToJsName(key, "git_" + typeDef.typeName); fnDef.jsFunctionName = Helpers.cTypeToJsName(key, "git_" + typeDef.typeName);
fnDef.jsClassName = typeDef.jsClassName;
if (fnDef.cppFunctionName == typeDef.cppClassName) { if (fnDef.cppFunctionName == typeDef.cppClassName) {
fnDef.cppFunctionName = fnDef.cppFunctionName.replace("Git", ""); fnDef.cppFunctionName = fnDef.cppFunctionName.replace("Git", "");
......
...@@ -102,6 +102,7 @@ void GitPatch::ConvenientFromDiffWorker::HandleOKCallback() { ...@@ -102,6 +102,7 @@ void GitPatch::ConvenientFromDiffWorker::HandleOKCallback() {
err = Nan::Error("Method convenientFromDiff has thrown an error.")->ToObject(); err = Nan::Error("Method convenientFromDiff has thrown an error.")->ToObject();
} }
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("Patch.convenientFromDiff").ToLocalChecked());
Local<v8::Value> argv[1] = { Local<v8::Value> argv[1] = {
err err
}; };
...@@ -119,6 +120,7 @@ void GitPatch::ConvenientFromDiffWorker::HandleOKCallback() { ...@@ -119,6 +120,7 @@ void GitPatch::ConvenientFromDiffWorker::HandleOKCallback() {
if (baton->error_code < 0) { if (baton->error_code < 0) {
Local<v8::Object> err = Nan::Error("method convenientFromDiff has thrown an error.")->ToObject(); Local<v8::Object> err = Nan::Error("method convenientFromDiff has thrown an error.")->ToObject();
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("Patch.convenientFromDiff").ToLocalChecked());
Local<v8::Value> argv[1] = { Local<v8::Value> argv[1] = {
err err
}; };
......
...@@ -87,6 +87,7 @@ void GitRemote::ReferenceListWorker::HandleOKCallback() ...@@ -87,6 +87,7 @@ void GitRemote::ReferenceListWorker::HandleOKCallback()
{ {
Local<v8::Object> err = Nan::Error("Reference List has thrown an error.")->ToObject(); Local<v8::Object> err = Nan::Error("Reference List has thrown an error.")->ToObject();
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("Remote.referenceList").ToLocalChecked());
Local<v8::Value> argv[1] = { Local<v8::Value> argv[1] = {
err err
}; };
......
...@@ -95,6 +95,7 @@ void GitRevwalk::FastWalkWorker::HandleOKCallback() ...@@ -95,6 +95,7 @@ void GitRevwalk::FastWalkWorker::HandleOKCallback()
err = Nan::Error("Method fastWalk has thrown an error.")->ToObject(); err = Nan::Error("Method fastWalk has thrown an error.")->ToObject();
} }
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("Revwalk.fastWalk").ToLocalChecked());
Local<v8::Value> argv[1] = { Local<v8::Value> argv[1] = {
err err
}; };
...@@ -159,6 +160,7 @@ void GitRevwalk::FastWalkWorker::HandleOKCallback() ...@@ -159,6 +160,7 @@ void GitRevwalk::FastWalkWorker::HandleOKCallback()
{ {
Local<v8::Object> err = Nan::Error("Method next has thrown an error.")->ToObject(); Local<v8::Object> err = Nan::Error("Method next has thrown an error.")->ToObject();
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("Revwalk.fastWalk").ToLocalChecked());
Local<v8::Value> argv[1] = { Local<v8::Value> argv[1] = {
err err
}; };
......
...@@ -296,6 +296,7 @@ void GitRevwalk::FileHistoryWalkWorker::HandleOKCallback() ...@@ -296,6 +296,7 @@ void GitRevwalk::FileHistoryWalkWorker::HandleOKCallback()
err = Nan::Error("Method fileHistoryWalk has thrown an error.")->ToObject(); err = Nan::Error("Method fileHistoryWalk has thrown an error.")->ToObject();
} }
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("Revwalk.fileHistoryWalk").ToLocalChecked());
Local<v8::Value> argv[1] = { Local<v8::Value> argv[1] = {
err err
}; };
...@@ -312,6 +313,7 @@ void GitRevwalk::FileHistoryWalkWorker::HandleOKCallback() ...@@ -312,6 +313,7 @@ void GitRevwalk::FileHistoryWalkWorker::HandleOKCallback()
if (baton->error_code < 0) { if (baton->error_code < 0) {
Local<v8::Object> err = Nan::Error("Method next has thrown an error.")->ToObject(); Local<v8::Object> err = Nan::Error("Method next has thrown an error.")->ToObject();
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("Revwalk.fileHistoryWalk").ToLocalChecked());
Local<v8::Value> argv[1] = { Local<v8::Value> argv[1] = {
err err
}; };
......
...@@ -107,6 +107,7 @@ void GitFilterRegistry::RegisterWorker::HandleOKCallback() { ...@@ -107,6 +107,7 @@ void GitFilterRegistry::RegisterWorker::HandleOKCallback() {
err = Nan::Error("Method register has thrown an error.")->ToObject(); err = Nan::Error("Method register has thrown an error.")->ToObject();
} }
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("FilterRegistry.register").ToLocalChecked());
v8::Local<v8::Value> argv[1] = { v8::Local<v8::Value> argv[1] = {
err err
}; };
...@@ -118,6 +119,7 @@ void GitFilterRegistry::RegisterWorker::HandleOKCallback() { ...@@ -118,6 +119,7 @@ void GitFilterRegistry::RegisterWorker::HandleOKCallback() {
else if (baton->error_code < 0) { else if (baton->error_code < 0) {
v8::Local<v8::Object> err = Nan::Error("Method register has thrown an error.")->ToObject(); v8::Local<v8::Object> err = Nan::Error("Method register has thrown an error.")->ToObject();
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("FilterRegistry.register").ToLocalChecked());
v8::Local<v8::Value> argv[1] = { v8::Local<v8::Value> argv[1] = {
err err
}; };
...@@ -191,6 +193,7 @@ void GitFilterRegistry::UnregisterWorker::HandleOKCallback() { ...@@ -191,6 +193,7 @@ void GitFilterRegistry::UnregisterWorker::HandleOKCallback() {
err = Nan::Error("Method register has thrown an error.")->ToObject(); err = Nan::Error("Method register has thrown an error.")->ToObject();
} }
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("FilterRegistry.unregister").ToLocalChecked());
v8::Local<v8::Value> argv[1] = { v8::Local<v8::Value> argv[1] = {
err err
}; };
...@@ -202,6 +205,7 @@ void GitFilterRegistry::UnregisterWorker::HandleOKCallback() { ...@@ -202,6 +205,7 @@ void GitFilterRegistry::UnregisterWorker::HandleOKCallback() {
else if (baton->error_code < 0) { else if (baton->error_code < 0) {
v8::Local<v8::Object> err = Nan::Error("Method unregister has thrown an error.")->ToObject(); v8::Local<v8::Object> err = Nan::Error("Method unregister has thrown an error.")->ToObject();
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("FilterRegistry.unregister").ToLocalChecked());
v8::Local<v8::Value> argv[1] = { v8::Local<v8::Value> argv[1] = {
err err
}; };
......
...@@ -161,6 +161,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() { ...@@ -161,6 +161,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
err = Nan::Error("Method {{ jsFunctionName }} has thrown an error.")->ToObject(); err = Nan::Error("Method {{ jsFunctionName }} has thrown an error.")->ToObject();
} }
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("{{ jsClassName }}.{{ jsFunctionName }}").ToLocalChecked());
v8::Local<v8::Value> argv[1] = { v8::Local<v8::Value> argv[1] = {
err err
}; };
...@@ -222,6 +223,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() { ...@@ -222,6 +223,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
if (!callbackFired) { if (!callbackFired) {
v8::Local<v8::Object> err = Nan::Error("Method {{ jsFunctionName }} has thrown an error.")->ToObject(); v8::Local<v8::Object> err = Nan::Error("Method {{ jsFunctionName }} has thrown an error.")->ToObject();
err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
err->Set(Nan::New("errorFunction").ToLocalChecked(), Nan::New("{{ jsClassName }}.{{ jsFunctionName }}").ToLocalChecked());
v8::Local<v8::Value> argv[1] = { v8::Local<v8::Value> argv[1] = {
err err
}; };
......
...@@ -1628,6 +1628,7 @@ describe("Merge", function() { ...@@ -1628,6 +1628,7 @@ describe("Merge", function() {
"should not be able to retrieve common merge base")); "should not be able to retrieve common merge base"));
}, function(err) { }, function(err) {
assert.equal("no merge base found", err.message); assert.equal("no merge base found", err.message);
assert.equal("Merge.base", err.errorFunction);
assert.equal(NodeGit.Error.CODE.ENOTFOUND, err.errno); assert.equal(NodeGit.Error.CODE.ENOTFOUND, err.errno);
}); });
}); });
......
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