Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose libgit2 error code to clients when a promise fails #1209

Merged
merged 3 commits into from
Feb 28, 2017

Conversation

rcjsuen
Copy link
Member

@rcjsuen rcjsuen commented Jan 31, 2017

This PR fixes up the C++ templates so that libgit2's error code is exposed on the JavaScript side by analyzing the rejected promise.

return git.Merge.base(repo, parents[0], parents[1])
.then(function(base) {
  // do whatever
})
.catch(function(err) {
  console.log(err);
  console.log(err.msg);
  console.log(err.errno);
});
// err
{ [Error: No merge base found] errno: -3 }
// err.msg
No merge base found
// err.errno
-3

When an API function of libgit2 fails within a promise, the promise is
rejected with a JavaScript Error object that wraps the recorded error
message in giterr_last(). However, the original non-zero return code of
the API function is not exposed to the caller of the NodeGit API. This
means that NodeGit clients cannot easily identify what the cause of an
error is outside of parsing the Error object's message. This is
an extremely volatile way of determining the cause as libgit2 may
choose to alter the wording of the message at any time.

To solve the problem above, the returned JavaScript Error object now
esposes the libgit2 error code via its `errno` property.
Copy link
Collaborator

@johnhaley81 johnhaley81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just conflicts that need to be resolved then this is GTG.

Merge in the latest changes and resolved a conflict by explicitly
referencing the v8 namespace when using Local types.
libgit2 has changed all their error messages to start with a
lowercased character. Updated the test to reflect this change.
@johnhaley81 johnhaley81 merged commit e66d20c into nodegit:master Feb 28, 2017
@rcjsuen rcjsuen deleted the errno branch April 12, 2017 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants