Nodegit: Nodegit.Reset.reset returns undefined

Created on 6 Jan 2018  路  2Comments  路  Source: nodegit/nodegit

Hi there,

I think that I've found a bug because Nodegit.Reset.reset(this.repo, headCommit, Nodegit.Reset.TYPE.HARD); returns undefined for me, according the spec it should return a code error. Could someone look on it?

Thanks for this lib, you did a great job! 馃挭

Example:

async reset() {
    await this.repo.fetchAll({
      callbacks: {
        credentials(_, userName) {
          return git.Cred.sshKeyNew(
            userName,
            '/Users/xxx/.ssh/id_rsa.pub',
            '/Users/xxx/.ssh/id_rsa',
            ''
          );
        },
      },
    });
    const headCommit = await this.repo.getHeadCommit();
    return git.Reset.reset(this.repo, headCommit, git.Reset.TYPE.HARD);
  }
Documentation

Most helpful comment

@jukben This issue is prevalent in a lot of NodeGit's functions. If there is an error the promise will be rejected.

Given the generated code below, you can assume that an error code of zero will resolve to undefined in the promise instead of a value of 0.

void GitReset::ResetWorker::HandleOKCallback() {
  if (baton->error_code == GIT_OK) {
    v8::Local<v8::Value> result = Nan::Undefined();
    v8::Local<v8::Value> argv[2] = {
      Nan::Null(),
      result
    };
    callback->Call(2, argv);
  } else {

All 2 comments

@jukben This issue is prevalent in a lot of NodeGit's functions. If there is an error the promise will be rejected.

Given the generated code below, you can assume that an error code of zero will resolve to undefined in the promise instead of a value of 0.

void GitReset::ResetWorker::HandleOKCallback() {
  if (baton->error_code == GIT_OK) {
    v8::Local<v8::Value> result = Nan::Undefined();
    v8::Local<v8::Value> argv[2] = {
      Nan::Null(),
      result
    };
    callback->Call(2, argv);
  } else {

Great - that info saved my life.. 馃槅
馃 I'd propose a fix for the documentation. Unfortunately i'm not able to build it. 馃槥

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DawsonG picture DawsonG  路  8Comments

pinoniq picture pinoniq  路  5Comments

seokju-na picture seokju-na  路  4Comments

elliottsj picture elliottsj  路  6Comments

Means88 picture Means88  路  5Comments