FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Expose libgit2 error code to clients when a promise fails by rcjsuen · Pull Request #1209 · nodegit/nodegit · GitHub

Repository navigation

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

johnhaley81 merged 3 commits into
nodegit:masterfrom
rcjsuen:errno

Conversation

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 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 merged commit e66d20c into nodegit:master Feb 28, 2017
rcjsuen deleted the errno branch April 12, 2017 12:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL