Skip to content

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

Merged
johnhaley81 merged 3 commits into
nodegit:masterfrom
rcjsuen:errno
Feb 28, 2017
Merged

Expose libgit2 error code to clients when a promise fails#1209
johnhaley81 merged 3 commits into
nodegit:masterfrom
rcjsuen:errno

Conversation

@rcjsuen

@rcjsuen rcjsuen commented Jan 31, 2017

Copy link
Copy Markdown
Member

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.

@johnhaley81 johnhaley81 left a comment

Copy link
Copy Markdown
Collaborator

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.

2 participants